SCJP 1.4, SCJD 1.4, SCWCD 1.3, SCBCD 1.3, IBM Certified Solution Developer -WebSphere Studio V5.0
SCJP 1.4, SCJD 1.4, SCWCD 1.3, SCBCD 1.3, IBM Certified Solution Developer -WebSphere Studio V5.0
public Object put(Object key,
Object value)
Associates the specified value with the specified key in this map. If the map previously contained a mapping for this key, the old value is replaced.
Thread 1 acquires a lock.
Thread 2 tries to lock the same record and goes into the wait state.
Thread 3 tries to lock the same record and goes into the wait state.
Thread 1 unlocks the record (probably it calls notifyAll).
Thread 2 leaves the "while(lockedRecords.containsValue(new Integer(recNo)))" loop and executes for example the lines
Then it is interrupted.
Thread 3 leaves the "while(lockedRecords.containsValue(new Integer(recNo)))" loop and locks the record.
Thread 2 continues and locks the record too!
SCJP 1.4, SCJD, SCWCD 1.4
The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
As Jay mentioned, you might have a problem if your testing code is attempting to have each client lock multiple records simultaneously, since your current code can only allow each client to lock one record at any given time.
Again, this may be handled by Dave's LockManager. It could throw RecordNotFound on it's put method and he may have handled that there. I have a very similar architecture for this part of the assignment. My LockManger class has a method lock (like the put method in Dave's code), but this will check to see if the record still exists on locking and throw the exception if not.There is the potential logic hole where a client gains a lock on a deleted record. That is: client A and B both try to lock record #5. Client A succeeds and deletes the record, then releases the lock. Client B then gains the lock on what is now a deleted record.
SCJP 1.4, SCJD, SCWCD 1.4
SCJP 1.4, SCJD 1.4, SCWCD 1.3, SCBCD 1.3, IBM Certified Solution Developer -WebSphere Studio V5.0
SCJP 1.4, SCJD, SCWCD 1.4
Straws are for suckers. Now suck on this tiny ad!
Smokeless wood heat with a rocket mass heater
https://woodheat.net
|