Java——打断睡眠阻塞

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

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_43442290/article/details/88973216