Machine-translated by Google. Questions are authored in English.
Top

Discussion

Which of these is the correct way to obtain a Condition?

  • A.Condition c = lock.getCondition();
  • B.Condition c = lock.newCondition();
  • C.Condition c = new Condition(lock);
  • D.Condition c = Condition.of(lock);

Answer: B

Correct answer: Condition c = lock.newCondition();

A Condition belongs to a particular lock and is obtained from it by newCondition(). Several conditions may be created on one lock, which is what makes it more flexible than the single wait set an intrinsic monitor provides.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.