LearnFrenzy
Sign in Take a free test

Concurrency and Executors · Concurrency and Executors MCQ · Question 15

Using ReentrantLock correctly Answer, explanation & discussion

  • MCQ
  • Easy
  • 0 comments
  • Answer explained
  • Moderated community
Question 15 Back to Exercise

Where should lock.unlock() be called?

  • A At the end of the method
  • B In a finally block after lock(), so the lock is released even if an exception occurs Correct
  • C Before lock()
  • D It is not needed
Correct Answer: Option B

Unlike synchronized, explicit locks are not released automatically.

Discussion & Comments 0

Share your method, a shortcut, or ask about a step you didn't follow.

No comments yet. Be the first to share your solution!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links