Java program for a daemon thread
KW.java
class KW extends Thread
{  
    public void run()
    {  
        if(Thread.currentThread().isDaemon())
        {
            System.out.println("Daemon Thread Running");  
        }  
        else
        {  
            System.out.println("Thread Running");  
        }  
    }  
    public static void main(String args[])
    {  
        KW t1=new KW();
        KW t2=new KW();  
        t1.setDaemon(true);
        t1.start();
        t2.start();    
    }  
}
Output
kodingwindow@kw:~$ javac KW.java
kodingwindow@kw:~$ java KW Daemon Thread Running Thread Running kodingwindow@kw:~$
Advertisement