Locks must be released if code exits a synchronized region and an exception being thrown is just one means of exiting a synchronized region. If locks weren't released when an exception is thrown, this would introduce the possibility (inevitability) for dead-lock in correctly written code.
-Nathan On 8/6/07, 史成荣 <[EMAIL PROTECTED]> wrote: > But it is said in Mark Stoodley's paper: Automatically Reducing Repetitive > Synchronization with a Just-in-Time Compiler for Java(cgo'05) that "The > exception handling infrastructure in IBM's JVM is already designed to track > objects as they are locked and unlocked. It automatically unlock any locked > objects when the exception occurs before any exception handler is executed > or before the frame is deleted if there is no handler for the exception in > the frame's method. This mechanism is orthogonal to synchronization > elimination. > In a JVM without such a mechanism, new catch blocks must be created to > explicitly unlock the object if an exception occurs." > And I had a look at chaprer 8 and 7.12 of JVM spec, didn't find any > description about the releasing of the lock(s) when the exception is > thrown. > > Thanks, > Chengrong >
