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.
enthuware.ocpjp.v11.2.1423
Moderator: admin
-
- Posts: 10
- Joined: Thu Apr 15, 2021 9:02 am
- Contact:
-
- Site Admin
- Posts: 10036
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: enthuware.ocpjp.v11.2.1423
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.
That is why it is important to call unlock() in finally.
You might want to go through a good book before attempting mock exams.
If you like our products and services, please help us by posting your review here.
-
- Posts: 10
- Joined: Thu Apr 15, 2021 9:02 am
- Contact:
Re: enthuware.ocpjp.v11.2.1423
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.
Thx.
Who is online
Users browsing this forum: Bing [Bot] and 56 guests