I cannot understand the usage and the purpose of daemon threads.
What are they for? How can I use them? Also, I tried to create daemons but I couldn't.
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) {
}
}
}
This is what I attempted so far, but it's not working properly.