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

📄 sleepinterrupt.java

📁 Java Thread Programming (Source
💻 JAVA
字号:
public class SleepInterrupt extends Object implements Runnable {
	public void run() {
		try {
			System.out.println(
					"in run() - about to sleep for 20 seconds");
			Thread.sleep(20000);
			System.out.println("in run() - woke up");
		} catch ( InterruptedException x ) {
			System.out.println(
					"in run() - interrupted while sleeping");
			return;
		}

		System.out.println("in run() - doing stuff after nap");
		System.out.println("in run() - leaving normally");
	}


	public static void main(String[] args) {
		SleepInterrupt si = new SleepInterrupt();
		Thread t = new Thread(si);
		t.start();

		// Be sure that the new thread gets a chance to 
		// run for a while.
		try { Thread.sleep(2000); } 
		catch ( InterruptedException x ) { }

		System.out.println(
				"in main() - interrupting other thread");
		t.interrupt();
		System.out.println("in main() - leaving");
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -