I have come up with the following locking implementation for URLyBIRD 1.3.1.
I am using the new Lock and Condition methodology in Java concurrent.locks package. I use a map bookings to hold records that are locked.
Appreciate any opinions if this looks good or see any issues? I think it is OK but just have worries I am missing something obvious. Also was not sure whether to use sgnal or signallAll in unlockRecord method.
First of all a remark regarding the readibility of this thread: try to limit the number of characters (e.g. 80) you put on 1 line (certainly when you use extensive comments). This will make your thread easier to read for other ranchers.
Secondly: these methods that you show, are this the implementations of Sun's interface you have to implement? Because I'm a regular visitor of this forum and I have never seen an interface where lock-method has a Data instance as a parameter. As far as I know you have 2 possible alternatives (recNo can also be a long):
And as a final remark: you can find in the ScjdFaq a link to an excellent test case to see if your solution is thread-safe. I suggest you have a look and test your solution using this test. And if you have any problems, post it here (or in that thread), because it's not our job to validate your locking mechanism. It 's something you should do on your own, because it's the most important (and hardest) part of the assignment.