Wednesday, February 25, 2009

Example code Daemon Thread



package thread;
class MyT extends Thread
{
public void run()
{
for(int i=0;i<10;i++)
{
System.out.println("childmethod");
try
{
Thread.sleep(2000);
}
catch(InterruptedException e) {}
}
}
}
public class DaemonThreadExample {
public static void main(String[]args)throws Exception
{
MyT t=new MyT();
System.out.println(t.isDaemon());
t.setDaemon(true);
System.out.println(t.isDaemon());
t.start();
Thread.sleep(5000);
System.out.println("end of main thread");
}
}

output:
false
true
childmethod
childmethod
childmethod
end of main thread



0 comments:

Post a Comment