Which method is used to create a daemon thread?


setDaemon(boolean value) – Set it to “true” to make thread as a daemon thread.


It is mandatory to call this method before thread start() method. All threads created by a programmers are user threads/normal threads unless you marked it as a daemon thread using the method setDaemon(boolean value).


Thread myDaemonThread = new Thread(new Runnable() {
public void run() {
// DoSomething();

/* Must call this method before start() */
myDaemonThread.setDaemon(true); /* set it true to mark as Daemon thread*/


Leave a Comment