如何创建守护进程线程?为了什么?
2022-09-02 14:19:08
我无法理解守护进程线程的用法和目的。
他们是干什么的?我该如何使用它们?另外,我试图创建守护进程,但我不能。
class Evil implements Runnable {
public static void main(String[] arg) throws Exception {
Thread t = new Thread(new Evil());
t.start();
Thread.sleep(1000);
t.setDaemon(true);//no success, error!
}
public void run() {
try {
Thread.sleep(1000);
System.out.println("How would it be Evil!?");
Thread.sleep(1000);
} catch (Exception e) {
}
}
}
这是我到目前为止尝试过的,但它不能正常工作。