aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Lock/Unlock in SCJD Exam with J2SE 1.4 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Lock/Unlock in SCJD Exam with J2SE 1.4" Watch "Lock/Unlock in SCJD Exam with J2SE 1.4" New topic
Author

Lock/Unlock in SCJD Exam with J2SE 1.4

Tom Elix
Greenhorn

Joined: Nov 03, 2002
Posts: 7
I am reading "The Sun Certified Java Developer Exam with J2SE 1.4". It gives examples for a lock and unlock mechanism (reserveDVD, releaseDVD) which don't fulfill this part of my exam instructions: "if an attempt is made to unlock a record that has not been locked by this connection, then no action is to be taken."
What am I missing here? (I am using RMI.)
Thanks,
Tom
Mag Hoehme
Ranch Hand

Joined: Apr 07, 2002
Posts: 194
Hi Tom,
I don't know the book you are referring to, so I can answer your question only partially. However, the instructions say that only the connection that has locked a record may unlock it. This means in the unlock() method you have to check the connection identity.
For example:
Connection 1 locks record n. Connection 2 attempts to release record n.
Result: Record n remains locked, because only connection 1 can release it.
Secondly: Stick to your instructions. It seems that there are different assignments around, the instructions of which differ slightly from each other!
Hope this helps.


Mag
Dave Teare
Ranch Hand

Joined: Oct 09, 2002
Posts: 80
How should we identify the clients such that we know who obtained the lock in the first place? Should each user be asked to enter an ID, or should the UI create some sore of UUID upon start up? Perhaps UUID=hostname + currentTime + randomNumber.
Any thoughts?
Thanks!
--Dave.
Mag Hoehme
Ranch Hand

Joined: Apr 07, 2002
Posts: 194
Hi Dave,
there are many solutions to this issue (and most of them have been discussed extensively in this forum). Here is how I did it: I had two sets of locking and unlocking methods. The first set required the record number plus an identifying object. The second set required only the record number and passed it on to the first set of methods, together with the current thread as identifying object.
However, the RMI specification explicitely says that you cannot rely on getting the same thread in subsequent method calls. For this reason I specified that the methods requiring only the record number should only be used for locking and unlocking within a single remote call. The second set should be used when more than one remote call is involved.
Hope this helps.
Max Habibi
town drunk
( and author)
Sheriff

Joined: Jun 27, 2002
Posts: 4118
Originally posted by Tom Elix:
I am reading "The Sun Certified Java Developer Exam with J2SE 1.4". It gives examples for a lock and unlock mechanism (reserveDVD, releaseDVD) which don't fulfill this part of my exam instructions: "if an attempt is made to unlock a record that has not been locked by this connection, then no action is to be taken."
What am I missing here? (I am using RMI.)
Thanks,
Tom

Hi Tom,
I may be able to help, since I wrote the book you're talking about. You're correct, the solution offered in the book is not an exact match for the solutions in the SCJD: we wanted to provide principles, not actual, literal answers. To be honest, we were afraid that we were too close as it was . That being said, I think you'll find that modifying that part of test will be trivial. Try using a map instead of a vector, and track your clients, either by assignning them a ticket number or keeping track of thier thread, and you'll be where you want to be.
All best,
M, author
The Sun Certified Java Developer Exam with J2SE 1.4


Java Regular Expressions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Lock/Unlock in SCJD Exam with J2SE 1.4