SCJP, SCJD, SCWCD, SCBCD
SCJP, SCJD, SCWCD, SCBCD
I'm thinking about the situation where the Sun auto-testing or some other program that might use my API is doing the calling to my Data manipulation methods. I wouldn't want any record locks left out there in an error situation, and I don't think I can really depend on them to remove the locks.
SCJP, SCJD, SCWCD, SCBCD
SCJP, SCJD, SCWCD, SCBCD
2. If exception is encountered within Data manipulation code, follow Ken's suggestion in the thread referenced above to unlock the record just to be safe since some big bad error must have occurred.
SCJP, SCJD, SCWCD, SCBCD
SCJP, SCJD, SCWCD, SCBCD
A possible one : Update/Delete are *not* responsible for unlocking.
Period.
In my ServicesImpl book method, which can throw RecordNotFoundException or IOException, I lock the Contractor record and then invoke my Data update method in a try block to perform the booking. If an exception is thrown during the Data update invocation, I catch it and then rethrow it after unlocking the Contractor in the finally block.
kktec<br />SCJP, SCWCD, SCJD<br />"What we observe is not nature itself, but nature exposed to our method of questioning." - Werner Heisenberg
SCJP, SCJD, SCWCD, SCBCD
My only question is lets say
you get a RecordNotFoundException. How can you then call unlock when
unlock also throws RecordNotFoundException. Unlock is just going to turn
around and throw it.
kktec<br />SCJP, SCWCD, SCJD<br />"What we observe is not nature itself, but nature exposed to our method of questioning." - Werner Heisenberg
Regards, George
SCJP, SCJD, SCWCD, SCBCD
Regards, George
SCJP, SCJD, SCWCD, SCBCD
Originally posted by james airey:
I like the try {} finally {} approach.
I did once find a compiler that wouldn't allow it without a catch clause though!
Regards, George
SCJP, SCJD, SCWCD, SCBCD
Consider Paul's rocket mass heater. |