class Thread1 implements Runnable
{
public void run()
{
for(int i=0;i<10;i++)
{
System.out.println("In Thread1 "+Thread.currentThread().getName() +" Is Executing");
}
}
}
public class ThreadJoin
{
public static void main(
String [] arg)
{
Thread1 t1=new Thread1();
Thread th1=new Thread(t1);
th1.setName("Lucy");
Thread th2=new Thread(t1);
th2.setName("Fred");
th1.start();
th2.start();
try
{
th2.join();
}
catch(InterruptedException e)
{
System.out.println(e);
}
}
}
in the above mentioned code join() is not performing as it should.
when Fred encounters ,it should halt the current thread execution until it
finishes it's own.
it's giving following output
C:\JAVADeepak\L9>
java ThreadJoin
In Thread1 Lucy Is Executing
In Thread1 Lucy Is Executing
In Thread1 Lucy Is Executing
In Thread1 Lucy Is Executing
In Thread1 Lucy Is Executing
In Thread1 Lucy Is Executing
In Thread1 Lucy Is Executing
In Thread1 Lucy Is Executing
In Thread1 Fred Is Executing ********Fred Enters
In Thread1 Fred Is Executing
In Thread1 Fred Is Executing
In Thread1 Fred Is Executing
In Thread1 Fred Is Executing
In Thread1 Fred Is Executing
In Thread1 Fred Is Executing
In Thread1 Fred Is Executing
In Thread1 Lucy Is Executing *********
In Thread1 Lucy Is Executing
In Thread1 Fred Is Executing *********
In Thread1 Fred Is Executing
Is there something wrong with code?
Thank You
Deepak Bahubal