⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 waitnotify.java

📁 Java网络编程与分布式计算, 主要分析java网络各方面的编程, 提供许多实用安全
💻 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 + -