-3

If a method is blocked at the wait statement, can another thread call the method/will the print statement be executed? Thanks

synchronised test() {
sysout("not blocked");
wait();
}
msietrterc
  • 89
  • 2
  • 8

1 Answers1

0

A common misconception is that the the method is locked. In fact the object this is locked. This means you can have the same method being called for different objects without using wait()

Conversely, if one thread obtains a lock, this will exclude any other locked section in any other method for this object.

A waiting thread releases the current lock so other methods can obtain a lock on the same object. This also means that thread must re-acquire the lock to stop waiting.

Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130