package day04;
/**
* 打断睡眠阻塞
* @author Administrator
*
*/
public class SleepDemo2 {
public static void main(String[] args) {
final Thread lin = new Thread() {
public void run() {
System.out.println("林:刚美容完,睡一会儿吧。");
try{
Thread.sleep(1000000);
}catch(InterruptedException e){
System.out.println("林:干嘛呢!干嘛呢!干嘛呢!都破了相了!");
}
System.out.println("林:醒了!");
}
};
Thread huang = new Thread() {
public void run() {
System.out.println("黄:开始砸墙!");
for(int i=0;i<5;i++) {
System.out.println("黄:80!");
try{
Thread.sleep(1000);
} catch (InterruptedException e) {
}
}
System.out.println("咣当!");
System.out.println("黄:搞定!");
lin.interrupt();//打断lin线程
}
};
lin.start();
huang.start();
}
}
Java——打断睡眠阻塞
最新推荐文章于 2024-06-13 22:06:57 发布