Actually, when will we set a thread to be a daemon thread?
I find that when all the non-daemon thread ends, even the daemon
thread is still running, the JVM will also stop.
<code>
public class hx implements Runnable {
public void run() {
try {
Thread.currentThread().sleep(10000);
}
catch(InterruptedException e) {}
for (int i = 0; i < 10; i++)
System.out.println(i);
}
public static void main(
String a[]) {
try {
Thread.currentThread().sleep(5000);
}
catch(InterruptedException e) {}
Thread t = new Thread(new hx());
t.setDaemon(true);
t.start();
}
}
</code>