This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Hum... no. Because, if record 1 is locked by client A, then when client B tries to lock it, it must not consume CPU cycles... with this approach of yours, it is consuming CPU cycles. In the lock method, while a record to be locked is already locked, then the client that is trying to lock it must wait().
Roberto Perillo wrote:while a record to be locked is already locked, then the client that is trying to lock it must wait(). .
Ok, so I have only that call a wait(), while my records lock map contains the record number. In a syncronized context clear.
OKOKOK, I am wrong, but, now while i have re-view the code, I have worked with a ReentrantLock, for this reason, the first thread that take the lock, work fine until lock.unlock.
So allways if there are anothers theads try take the lock can´t because already is lock, only when the current thread release the lock, another thread can execute the lock block code.
Now this approuch is like SCJD exam with J2SE by Monkhouse.
in my block code, is verify that record number is a valid record in database through read(recNo). but I trhow a securityException when record is locked with another lockCookie
this is the reason because I have throw a SE if already is lock some register for a second client.
So i have not consuming cpu cicles thanks to use lock.lock and lock.unlock (reentrantLock) and also i have validate that map contains a lock cookie for fist client that obtain the lock.
sorrry for my fist expose in post, but is good have a re-view for code, at this moment i have re-view all!