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();
}
}
}