enthuware.ocpjp.v11.2.1423
Posted: Sat Apr 17, 2021 6:44 pm
Justification for the said question :
The Java exception mechanism is integrated with the Java synchronization model, so that locks are released if synchronized statements and invocations of synchronized methods complete abruptly. Note that this does not apply to java.util.concurrent.locks.Lock. These locks must be released by the programmer explicitly and the recommended pattern of usage is as follows: Lock l = ...; l.lock(); try { // access the resource protected by this lock } finally { l.unlock(); }
What if we don't release the java.util.concurrent.locks.Lock and exception occurs in try block.
Thx.
The Java exception mechanism is integrated with the Java synchronization model, so that locks are released if synchronized statements and invocations of synchronized methods complete abruptly. Note that this does not apply to java.util.concurrent.locks.Lock. These locks must be released by the programmer explicitly and the recommended pattern of usage is as follows: Lock l = ...; l.lock(); try { // access the resource protected by this lock } finally { l.unlock(); }
What if we don't release the java.util.concurrent.locks.Lock and exception occurs in try block.
Thx.