• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Lock/Unlock in SCJD Exam with J2SE 1.4

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 194
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 194
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
town drunk
( and author)
Posts: 4118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
And will you succeed? Yes you will indeed! (98 and 3/4 % guaranteed) - Seuss. tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic