source code to demonstrate join method
package thread;
class MyThr extends Thread
{
public void run()
{
for(int i=0;i<3;i++)
{
System.out.println("child thread");
try
{
Thread.sleep(1000);
}
catch(InterruptedException e){}
}
}
}
public class ThreadDem
{
public static void main(String a[])throws Exception
{
MyThr t=new MyThr();
t.start();
t.join(); //or t.join(3000);
for(int i=0;i<2;i++);
{
System.out.println("main thread");
}
}
}
output:
child thread
child thread
child thread
main thread
main thread
0 comments:
Post a Comment