wood burning stoves 2.0*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Also about clientid and unclock Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Also about clientid and unclock" Watch "Also about clientid and unclock" New topic
Author

Also about clientid and unclock

Gerald Kou
Greenhorn

Joined: Jun 03, 2003
Posts: 14
I saw some posts about "clientid"'s role.They said that using of clientid can prevent the case as below:
A.lock(27)
..
B.unlock(27)
A.unlock(27)
But I doubted it beacase the sequence of execution is lock-reade-modify-unlock.So if Thread A locked one record suceessfully,then Thread B can't locked the same record.Thread B should blocked in lock() method untill Thread A finish unlock() and notifyAll().
Am I wrong? Please tell me why to use clientid?
John Smith
Ranch Hand

Joined: Oct 08, 2001
Posts: 2937
So if Thread A locked one record suceessfully,then Thread B can't locked the same record.Thread B should blocked in lock() method untill Thread A finish unlock() and notifyAll().
Am I wrong? Please tell me why to use clientid?

The problem is not with locking, but with the unlocking. There is an explicit requirement in your instructions (or the javadoc for unlock()) that only the client who locked a particular record can unlock it. The only way to accomplish it is to track the clients.
[ June 26, 2003: Message edited by: Eugene Kononov ]
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
Well, that depends on your assignment. Many of the current assignments use "cookies" instead. When you lock a record, the method returns a unique long value - and if you want to unlock the record later, you have to provide the correct cookie for that record. Which is a rather irritating API to use, but we're explicitly required to use it. (Well, many of us are - requirements vary in subtle ways.) So, if your assignment uses cookies, the requirement is not that "only the client that unlocked the record can unlock it" but rather "Cookie must be the cookie
returned when the record was locked; otherwise throws SecurityException." Which means that once you've implemented this odd scheme, there's not really any need for clientID any more.
So - maybe you have a use for it, maybe you don't. Read your assignment carefully and analyze.


"I'm not back." - Bill Harding, Twister
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Also about clientid and unclock
 
Similar Threads
Deadlock during record locking
B&S no lock cookies
DBMain interface: lock - delete - unlock or lock/unlock within delete?
Locks without Client IDs?
About thread safe...