Karen Smrha

Greenhorn
+ Follow
since Nov 13, 2008
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Karen Smrha

Martin,

I have B&S and decided to use my contractor value object everywhere including in my JTable's model.

I did not make my JTable's model generic; it only supports the one value object. As you said, there is no point putting too much working into a GUI that will be replaced.

I do not like DBMain so I use Data as an adapter to my new interface. This means Data is the only class that uses String[]; the rest all use the value object.

I have not uploaded my project yet, so I cannot tell you if SUN is going to like my approach - fingers crossed.

Good luck,
Karen Smrha
Mohini,

I also have B&S 2.3.1. The database file I received from SUN
does NOT have unique contractor names. I don't recommend
using name alone as your primary key in case they test
you system with a database file like mine.

I have chosen to use the recordId as my primary key and
I store this in my contractor value object. This is a
simple solution. Some people use a composite primary key
made of of name/location or name/location/specialties.

Good luck,
Karen Smrha
Bob,

Thanks!!

I see from your signature you have have passed. Congratulations!

If SUN did not force you to make clients to wait on locks they aready have, I should be ok. It's a relief to hear from someone who has passed. I plan to upload in a couple weeks so I am getting nervous.

Congratulations and have a great summer!
Karen
P.S. Can you send some Brasilian sun to the Netherlands. It's cold here.


-----------------


From Jeffry Kristianto Yanuar
The word "the CPU must give up the CPU and consumes no CPU cycle" means that the client thread must wait undefinitely until the other client release the lock.



Jeffry,

I do make clients wait if "a different client" has locked the record.

It's only when the same client already has the lock that I return successfully. I don't make them wait on a lock they already have.

My instructions say "wait if locked" (not "wait if locked by other client) so I was unsure if SUN's instructions force me to make a client wait on a lock it already has.

I hope you get your results quickly and they are good!
GOOD LUCK!
Karen
Bob,

Do your instructions have something like this?


//If the specified record is already locked, the current thread gives up
//the CPU and consumes no CPU cycles until the record is unlocked.
public void lock(int recNo) throws RecordNotFoundException;



or do you have something like this?


//If the specified record is already locked by another client,
// the current thread gives up
//the CPU and consumes no CPU cycles until the record is unlocked.
public void lock(int recNo) throws RecordNotFoundException;



I have the first one. I worry about flunking if I miss a SUN "must" requirement.

The method description does not say "must", but I have a "must" implement this interface so I am unsure if this only means "must" implement method signature (I do) or if it also means "must" implement method description (I don't make clients wait on locks they have).

Thanks,
Karen Smrha
I am worried about following my instructions correctly and would appreciate your opinion.

I don't want a client to wait on a locked record if that same client already has the lock. So instead of making the client wait, I ignore the request and return.

I documented this in javadoc and choices.

My instructions contain:


Your data access class must be called "Data.java", must be in a package called "suncertify.db", and must implement the following interface:
.
.
//If the specified record is already locked, the current thread gives up
//the CPU and consumes no CPU cycles until the record is unlocked.
public void lock(int recNo) throws RecordNotFoundException;
.
.
"Any attempt to lock a resource that is already locked should cause the current thread to give up the CPU, consuming no CPU cycles until the desired resource becomes available."



I am worried about flunking a "must do". Do you think this means I really have to make the client wait on a lock it already has?

Thank you for your help,
Karen Smrha
[ November 26, 2008: Message edited by: Karen Smrha ]
Alecsandru,

Thanks for posting your multi-thread test. I will run it; the more testing the better. I also have a 3-tier design. You are right, SUN will hit our database tier as hard as they can and will do things our application cannot.

In case you haven't seen it, here's another test:
https://coderanch.com/t/189353/java-developer-SCJD/certification/JUnit-Test-Cases


Originally posted by: Alecsandru Cocarla
Not really. The code is in the same class, and, anyway, such decision is not taken over night. Everything involving multithreading should be carefully thought/tested before doing so. For example, even with your approach, if the junior forgets to lock on the masterLock, then it's still possible to break the application. If, doing so, he also sets the cookie to null or if you don't have a timeout, then again, it's a very big problem.



Yes, junior programmers can mess up complicated code quite easily.

I added implementation comments defining locking requirements: locking order (master/record), must hold master to lock record, modify map, check waiting threads... That plus cleaning up code/design so its easier to understand is how I hope to satisfy SUN's junior programmer requirement.

- Karen Smrha
The difference is:






I am not sure if there is any real difference if your system never removes record locks from the collection.

If you do release the master before getting the record-level lock, I suggest adding an implementation comment explaining this. Otherwise, someone else working on the code might decide to add code that removes entries from the collection and breaks your locking.


Of course there is one issue with this approach, where is remove()? Map with locks may grow and grow to the size equal to number of records in db. That's the scalability problem. Did anyone solved that?



I added lock removal to my unlock method. If the record doesn't exist in the DBMS and there are no waiting threads, I remove it.

You need to hold the master lock to check the number of waiting threads and remove the entry. Otherwise, a new waiting thread may be added while you are working.

So far, my code seems ok, but I think I need run a test with many threads working on a single record with some of them deleting it.

- Karen Smrha
Please correct me if I am wrong, but I think if you use record level locks you do need hand-over-hand locking. The master lock is what locks the collection containing your row locks.

If the collection was read-only, we would not need to lock it, but lock() add elements and unlock (if you implement lock removal for deleted records) removes elements. We need a safe way to modify the collection in a multi-threaded environment.
I also recommend logging, but be careful if you are writing to a file.

It could be that the person checking your project runs in a
directory without write permission. Your code should check
if it has write permission.

Good luck,
Karen Smrha
Martin,

You asked about the search (exact match) for the GUI vs. the
starts with search defined in DBMain.

Which one should I implement? It would very silly to implement the db in a way that finds partially matched criterias and then filter those results to provide exact matches only.



Your Data class must contain a find
method that exactly matches the functionality and signature defined
in your instructions. SUN tests your GUI and they also directly
connect to you Data class to check that DBMain is implemented.

DBMain is an ugly interface. Design-wise you need to decide how
you want to handle these limitations. The simplest solution is
to "work with the limitations". For searching that would mean
that whatever calls Data has to filter the results.

If you want to have your database provide "exact match" searching
you need to design your system so that it implements
"more than just DBMain".

One option is to have a second interface that
provides extra and/or overloaded methods. The second
interface can extend DBMain so that Data implements all
of the methods SUN expects plus the ones you added.

There are many useful design discussion on this forum.
If you are not in a rush, I recommend taking time to think about
your design and draw it on paper before you start coding.

Good luck with your project,
Karen
I am almost finished and am preparing for the upload.

The FAQ says that we must give our

purchase confirmation number

if we have trouble uploading.

I was never given a confirmation number. The local SUN office says I must contact SunCert@prometric.com. I have tried, but they have not responded after 2 emails and 2 weeks.

Did any of you get a

purchase confirmation number

?
Is this different from the prometric test ID number?

Is it normal for SUN to be so slow with email? I am now worried about having to email my request for upload permission.

Thank you for you help,
Karen Smrha

PS This is my first posting. Sorry, if the above formatting has trouble.