Java Program on Daemon Thread
Get Job-ready: Java Course with 45+ Real-time Projects! - Learn Java
Program 1
package dataflair;
public class TestMain
{
public static void main(String[] args) throws InterruptedException
{
System.out.println("This is main Thread...");
System.out.println("Main Thread Status: "+Thread.currentThread().isDaemon());
MyThread mt1=new MyThread();
mt1.setDaemon(true);
mt1.start();
System.out.println("Child Thread Status: "+mt1.isDaemon());
System.out.println("Main Thread Status: "+Thread.currentThread().isDaemon());
Thread.sleep(10000);
}
}Program 2
package dataflair;
public class MyThread extends Thread
{
public void run()
{
try
{
System.out.println("This is child Thread: ");
for (int i = 1; i <= 10; i++)
{
System.out.println("Child Thread: "+i);
Thread.sleep(1000);
}
}
catch(InterruptedException e)
{
System.out.println(e);
}
}
}
You give me 15 seconds I promise you best tutorials
Please share your happy experience on Google

