I have one question regarding wait/notify based threads interaction.
The output of the below code is Im
. How output can be Im
as there is no other thread calling notify()
on Thread object. Is it like JVM implicitly calls notify()
in above such scenarios where you try to wait on Thread class instance.
A thread operation gets stuck when it waits without receiving any notification. Now what if I wait on Thread class instance wait()
. For e.g.
public class WaitingThread {
public static void main(String[] args) {
Thread t1 = new Thread();
t1.start();
synchronized (t1) {
try {
t1.wait();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
System.out.println("Im");
}
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…