public class SleepDemo2 {
public static void main(String[] args) {
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("黄:开始砸墙.....");
try {
for (int i=0;i<5;i++){
System.out.println("80!");
Thread.sleep(1000);
}
} catch (InterruptedException e) {
}
System.out.println("砸完了!");
lin.interrupt();//中断lin的睡眠阻塞!
}
};
lin.start();
huang.start();
}
}
红色字体主要体现interrupt()阻塞方法