当我在线程对象上调用wait()方法时,同步线程完成运行后,等待的线程将被唤醒,为什么线程对象的行为不同于其中wait()的普通对象的行为?
Thread thread1 = new Thread(()-> {
System.out.println("thread 1 start");
try {
Thread.sleep(3000);
System.out.println("thread over");
} catch (InterruptedException e) {
e.printStackTrace();
}});
thread1.start();
synchronized (thread1) {
try {
thread1.wait();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
System.out.println("main thread wake up");
Run Code Online (Sandbox Code Playgroud)
我希望3s之后主线程不会唤醒,但是不会。