I actually added the finally block today at work, so I still have the old one at home. It runs and completes at home too. (I'm there now and just re compiled and ran it). I use a LockManager class. My Data (facade) to my DataFileAccess(singleton), just does checks for deleted record and I compare TotalRecords.length against the record number to make its not greater than the highest record number or negative (invalid record either way). Here's some pseudo of my lock/unlock (without the Finally).
Lock:
createCookie
synchronize on HashMap of record numbers/cookies
see if it's already locked and if it is
try
wait
catch Interrupted
if it's not locked
go ahead and put the key/value pair into the static HashMap
Unlock:
synchronize the HashMap
while the record number is in the HashMap
if it is, do a get on recordNumber and check the cookie returned with equals(cookie)
if it passes that
test, go ahead and remove it from the HashMap
NotifyAll
if the cookie doesn't equal lockCookie, throw SecurityException
I'll let you take a look at that before figuring out the finally thing. I've seen quite a few posts that it is a good idea to always unlock in finally. I did a major search on Locking and logical locking today! Can you take a look at the doubleLock and wait
thread? I think his code is basically right, but I haven't passed yet, and you aced the Locking part, so should be able to tell right away if it's OK. Thanks!