The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
believe you are doing FBNS. Is that correct?
If so, you have changed the lock() method signature to include a RecordNotFoundException - have you specified why you added this in your documentation?
The if statement in the following code appears redundant. Why do you have both an if statement and a while statement that are doing the same check?
SCJP 1.2, OCP 9i DBA, SCWCD 1.3, SCJP 1.4 (SAI), SCJD 1.4, SCWCD 1.4 (Beta), ICED (IBM 287, IBM 484, IBM 486), SCMAD 1.0 (Beta), SCBCD 1.3, ICSD (IBM 288), ICDBA (IBM 700, IBM 701), SCDJWS, ICSD (IBM 348), OCP 10g DBA (Beta), SCJP 5.0 (Beta), SCJA 1.0 (Beta), MCP(70-270), SCBCD 5.0 (Beta), SCJP 6.0, SCEA for JEE5 (in progress)
SCJP 1.2, OCP 9i DBA, SCWCD 1.3, SCJP 1.4 (SAI), SCJD 1.4, SCWCD 1.4 (Beta), ICED (IBM 287, IBM 484, IBM 486), SCMAD 1.0 (Beta), SCBCD 1.3, ICSD (IBM 288), ICDBA (IBM 700, IBM 701), SCDJWS, ICSD (IBM 348), OCP 10g DBA (Beta), SCJP 5.0 (Beta), SCJA 1.0 (Beta), MCP(70-270), SCBCD 5.0 (Beta), SCJP 6.0, SCEA for JEE5 (in progress)
However, if we synchronized locker in lock(), even if other thread wanna release their lock, they cannot do so becos it is hold by the current thread. Am I correct?
SCJP 1.2, OCP 9i DBA, SCWCD 1.3, SCJP 1.4 (SAI), SCJD 1.4, SCWCD 1.4 (Beta), ICED (IBM 287, IBM 484, IBM 486), SCMAD 1.0 (Beta), SCBCD 1.3, ICSD (IBM 288), ICDBA (IBM 700, IBM 701), SCDJWS, ICSD (IBM 348), OCP 10g DBA (Beta), SCJP 5.0 (Beta), SCJA 1.0 (Beta), MCP(70-270), SCBCD 5.0 (Beta), SCJP 6.0, SCEA for JEE5 (in progress)
But T1 will wait at the POINT X, becos, by refering to T2, T2 enters the critical section, so T1 cannot enter into it.
The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
Are you sure your lock() method may throw an IOException ?
Your first call to validateRecord() is useless IMO. Think of the fact that if the record is invalid, nobody will have a lock on it, in such a way that you won't wait for it.
Your second call to validateRecord() should go out of the while loop (just before lockedRecords.add()) : your goal is not to validate the record each time you get a chance to grab the lock, but when you actually can do it.
I see a big issue with the way you get a database lock : let's say that T1 owns a db lock and T2 and T3 are waiting for such a db lock. When T1 will release its db lock, T2 *AND* T3 will be granted the db lock. You should replace the if(dbLockRequest) by a while(dbLockRequest).
Also, you have a requirement that only the client that locks a record may unlock it. How are you handling that? (I suspect that you are handling it the same way I handled it (and therefore I think you are right ) - but I just want to check that you have not forgotten about that requirement).
And then we all jump out and yell "surprise! we got you this tiny ad!"
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
|