Page 1 of 1

enthuware.ocpjp.v11.2.1423

Posted: Sat Apr 17, 2021 6:44 pm
by ketank
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.

Re: enthuware.ocpjp.v11.2.1423

Posted: Sun Apr 18, 2021 12:40 am
by admin
It will remain locked! It may lead to a deadlock later on.
That is why it is important to call unlock() in finally.
You might want to go through a good book before attempting mock exams.

Re: enthuware.ocpjp.v11.2.1423

Posted: Sun Apr 18, 2021 4:42 am
by ketank
Thanks for the inputs. I am short on time so instead of reading a book I have gone through a course. I am getting ~65-70% on mocks. I am working on weak links. Have exam scheduled for tonight.

Thx.