📄 waitnotify.java
字号:
// Chapter 7, Listing 9
public class WaitNotify extends Thread
{
public static void main(String args[]) throws Exception
{
Thread notificationThread = new WaitNotify();
notificationThread.start();
// Wait for the notification thread to trigger event
synchronized (notificationThread)
{
notificationThread.wait();
}
// Notify user that the wait() method has returned
System.out.println ("The wait is over");
}
public void run()
{
System.out.println ("Hit enter to stop waiting thread");
try
{
System.in.read();
}
catch (java.io.IOException ioe)
{
// no code req'd
}
// Notify any threads waiting on this thread
synchronized (this)
{
this.notifyAll();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -