Forums Register Login

Lock/Unlock in SCJD Exam with J2SE 1.4

+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
 

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
This is my favorite tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 704 times.
Similar Threads
Hand-over-hand locking not needed in SCJD book example ?
How to identify client?
my choice on lock/unlock.help me to decide,Eugene and Andrew
Connection Factory pls explain
passed developer exam 144/155!!
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 13:13:58.