deamon守护线程

线程分为用户线程和守护线程

守护线程为用户线程服务,如gc ,监控线程等

jvm不需要等待守护结束再关闭,但是必须等待用户线程结束;

package y.i.d;

public class TestDaemon {
	public static void main(String[] args) {
		You1 you1=new You1();
		God god=new God();
		Thread y1=new Thread(you1);
		
		Thread god1=new Thread(god);
		god1.setDaemon(true);
		y1.start();
		god1.start();
	}
}

class You1 implements Runnable{
	@Override
	public void run() {
		for (int i = 0; i <10; i++) {
			System.out.println("happy year");
		}
		System.out.println("挂了");
	}
}

class God implements Runnable{
	@Override
	public void run() {
		while(true) {
			System.out.println("god bless you");
		}
	}
}
发布了189 篇原创文章 · 获赞 10 · 访问量 6万+

猜你喜欢

转载自blog.csdn.net/wangrong111222/article/details/101161266