线程休眠

package com.lxxu.testthread;

public class ThreadDemo9 {
	/**
	 *
	 * @throws InterruptedException
	 */
	public static void main(String[] args) throws Exception {

		Thread thread = new Thread(() -> {
			System.out.println("我要休息10秒");
			try {
				Thread.sleep(10000);
				System.out.println("休息好了");
			} catch (InterruptedException e) {
				System.out.println("真烦!");
			}
		});
		thread.start();
		Thread.sleep(1000);
		if (!thread.isInterrupted()) {
			System.out.println("打扰了!");
			thread.interrupt();
		}

	}
}

猜你喜欢

转载自blog.csdn.net/qq_42740745/article/details/84670930