From Jeffry Kristianto Yanuar
The word "the CPU must give up the CPU and consumes no CPU cycle" means that the client thread must wait undefinitely until the other client release the lock.
//If the specified record is already locked, the current thread gives up
//the CPU and consumes no CPU cycles until the record is unlocked.
public void lock(int recNo) throws RecordNotFoundException;
//If the specified record is already locked by another client,
// the current thread gives up
//the CPU and consumes no CPU cycles until the record is unlocked.
public void lock(int recNo) throws RecordNotFoundException;
Your data access class must be called "Data.java", must be in a package called "suncertify.db", and must implement the following interface:
.
.
//If the specified record is already locked, the current thread gives up
//the CPU and consumes no CPU cycles until the record is unlocked.
public void lock(int recNo) throws RecordNotFoundException;
.
.
"Any attempt to lock a resource that is already locked should cause the current thread to give up the CPU, consuming no CPU cycles until the desired resource becomes available."
Originally posted by: Alecsandru Cocarla
Not really. The code is in the same class, and, anyway, such decision is not taken over night. Everything involving multithreading should be carefully thought/tested before doing so. For example, even with your approach, if the junior forgets to lock on the masterLock, then it's still possible to break the application. If, doing so, he also sets the cookie to null or if you don't have a timeout, then again, it's a very big problem.
Of course there is one issue with this approach, where is remove()? Map with locks may grow and grow to the size equal to number of records in db. That's the scalability problem. Did anyone solved that?
Which one should I implement? It would very silly to implement the db in a way that finds partially matched criterias and then filter those results to provide exact matches only.
if we have trouble uploading.purchase confirmation number
?purchase confirmation number