Monday, March 2, 2015

Daemon Thread

A Daemon Thread is a thread that runs in the background, JVM stops if all the user threads are stopped and doesn't bother about the daemon thread. Used for garbage collection, clock handler

 
package Threadsdeamon;

public class mainclass {

 public static void main(String[] args) {
  // TODO Auto-generated method stub
  Thread t=new Thread1();
  Runnable t2=new Thread2();
  t.setDaemon(true);
  t.start();
  new Thread(t2).start(); 
  
  if(t.isDaemon()){
   System.out.println("Daemon thread is still alive");
  }
 }

}


>>>
------------------------------------------------------------------------------------------------------------

No comments:

Post a Comment