Hello everyone,
Please look at the following code block,
public void Foo()
{
synchronized (lock)
{
//do task 1
try {
lock.wait();
} catch (InterruptedException e) {
// TODO Auto-generated catch lock
e.printStackTrace();
}
//do task 2
}
}
Suppose multiple threads have entered the synchronized block one by one, and then they all release the lock by invoking "wait" on lock object. If sometime later "notifyAll" of the lock object is invoked, all the threads which have been waiting for the lock will be awakened. Then there will be multiple threads executing task 2 (the task just after the wait statement), but task 2 is in a synchronized block, how can multiple threads enter a synchronized block?
Are there anything wrong in my previous statement and the code block?
Thanks in advance,
George