This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Doubt in Locking Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Doubt in Locking" Watch "Doubt in Locking" New topic
Author

Doubt in Locking

rohan tiwari
Ranch Hand

Joined: Sep 13, 2007
Posts: 82
I am done with the coding of my project..URLYBird 1.1.2.It took me 120 hrs approx.
I have a requirement for my lock method which states that:
"If the specified record is already locked by a different
client, the current thread gives up the CPU and consumes no CPU cycles until the record is unlocked".

I have implemented timeout and reentrant locks in my reservation lock manager class . I think that if a thread conditionally waits for a short timeout or until a lock is released (whichever comes earlier) would not consume CPU cycles,since after the timeout the thread gives up as opposed to blocking continously until the lock is released.


Is my understanding correct ?


SCJP 5, SCWCD 1.4, SCJD 5
Musab Al-Rawi
Ranch Hand

Joined: Aug 06, 2007
Posts: 231
I think you should NOT use timeouts based on my understanding from the Monkhouse's book and posts.
Pay attention to the part where it says "by another client" if it is written in the assignment this means that if the client is trying to lock a record that is already locked by itself the client should not wait.


SCBCD - SCWCD - SCJD - SCJP - OCA
rohan tiwari
Ranch Hand

Joined: Sep 13, 2007
Posts: 82
Thanks..
I have removed timeouts.
John R Roberts
Ranch Hand

Joined: Dec 27, 2006
Posts: 36
Like you my solution used the ReentrantLock and Condition classes, NO timeouts.
I obtained 80/80 in the locking portion of the exam. Sounds like your taking a good approach.
 
wood burning stoves
 
subject: Doubt in Locking
 
Similar Threads
Urly Bird "void" return type of lock() - how to know if locking succeeded?
Elegant solution to waiting without CPU activity?
Deadlock during record locking
Timeouts for logical record locking and multiple notification objects
DeadLock