waitnotify.java
来自「Java网络编程与分布式计算, 主要分析java网络各方面的编程, 提供许多实用」· Java 代码 · 共 40 行
JAVA
40 行
// 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 + =
减小字号Ctrl + -
显示快捷键?