Java Thread.setDaemon(boolean on)

Syntax

Thread.setDaemon(boolean on) has the following syntax.

public final void setDaemon(boolean on)

Example

In the following code shows how to use Thread.setDaemon(boolean on) method.


class MyThread extends Thread {
   MyThread() {//w  ww  . j  a  v a 2s .co m
      setDaemon(false);
   }
   public void run() {
      boolean d = isDaemon();
      System.out.println("daemon = " + d);
   }
}

public class Main {

  public static void main(String[] args) throws Exception {
    
    Thread thread = new MyThread();
    System.out.println("thread = " + thread.currentThread());
    thread.setDaemon(false);
   
    thread.start();
  }
}




















Home »
  Java Tutorial »
    java.lang »




Boolean
Byte
Character
Class
Double
Enum
Float
Integer
Long
Math
Number
Object
Package
Process
ProcessBuilder
Runnable
Runtime
SecurityManager
Short
StackTraceElement
StrictMath
String
StringBuffer
StringBuilder
System
Thread
ThreadGroup
ThreadLocal
Throwable