Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
Node is saved as draft in My Content >> Draft
  • How to create Daemon Thread ?

    • 0
    • 1
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 471
    Comment on it

    Daemon Thread:

    These are those thread which execute in background in support of main Thread (creator of that Thread). Life of a Daemon Thread is up-to life of main Thread which start the dameon thread. This daemon thread have very low priority. If we want to make any thread to daemon thread, then don't start the thread hence otherwise it will throw IllegalThreadStateException.

     

     

        public class Dameon_Thread extends Thread{  
         public void run(){  
          if(Thread.currentThread().isDaemon()){//checking for daemon thread  
           System.out.println("daemon thread work");  
          }  
          else{  
          System.out.println("user thread work");  
         }  
         }  
         public static void main(String[] args){  
        	 Dameon_Thread ob1=new Dameon_Thread(); //creating threads
        	 Dameon_Thread ob2=new Dameon_Thread();
        	 Dameon_Thread ob3=new Dameon_Thread();
          
          ob1.setDaemon(true);//setting ob1 to daemon thread  
            
          ob1.start();//starting threads  
          ob2.start();  
          ob3.start();  
         }  
        }  

     

    Daemon Thread

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: