A thread must be marked as a daemon thread before it is started. : Daemon « Threads « Java






A thread must be marked as a daemon thread before it is started.

 


class MyThread extends Thread {
  MyThread() {
    setDaemon(true);
  }

  public void run() {
    boolean isDaemon = isDaemon();
    System.out.println("isDaemon:" + isDaemon);
  }
}

public class Main {
  public static void main(String[] argv) throws Exception {
    Thread thread = new MyThread();
    thread.setDaemon(true);
    thread.start();
  }
}

   
  








Related examples in the same category

1.A daemon thread.
2.An application exits when there are no non-daemon threads running.
3.A live daemon thread does not prevent an application from exiting.