多线程管理

线程状态

线程相关Api

线程终止

线程分类


守护线程不是自己关闭的情况下,强制终止资源会得不到释放。

package daemon;

public class ThreadDemo4
{
	public static void main(String args[]) throws InterruptedException
	{
		TestThread4 t = new TestThread4();
		t.setDaemon(true);//守护线程开启
		t.start();
		Thread.sleep(2000);
		System.out.println("main thread is exiting");
	}
}
 class TestThread4 extends Thread
{
	public void run() 
	{
		while(true)
		{
			System.out.println("TestThread4" + 
			" is running");
			try {
				Thread.sleep(1000);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}
} 
posted @ 2020-01-29 17:39  浅滩浅  阅读(171)  评论(0编辑  收藏  举报