java multithreading - daemon thread

Daemon thread daemon, is for the user thread services, the start before setting
default user thread is a thread in our
thread into thread and thread guard user
virtual machine must ensure that the user is finished thread
virtual machine without waiting for the daemon thread is finished
as background operation log records, monitor memory usage etc.
Thread object .setDaemon (true); default is false

public class n {

public static void main(String[]args) throws InterruptedException
{
    test t=new test();
    test2 t2=new test2();

    new Thread(t).start();

    Thread tt2=new Thread(t2);
    tt2.setDaemon(true);//在t用户线程结束后结束
    tt2.start();

}
}
class test implements Runnable
{
public void run()
{
    for(int i=1;i<=365*100;i++)
    {
        System.out.println("me");
    }
    System.out.println("he");
}
}
class test2 implements Runnable{
public void run()
{
    for(;true;)
    {
        System.out.println("she");
    }
}
}

Guess you like

Origin blog.51cto.com/14437184/2428993