isAlive : This method is used to check whether a thread is in the running state or not .
Join : This method is use to specify the time you want to wait for the specified thread to terminate .
Example :
class Demo
{
String arr[]={"Here comes the I'st child ",
"Here comes the II'nd child",
"Here comes the III'rd child"};
public void run()
{
try
{
for(int i=0;i<3;i++)
{
Thread.sleep(3000);
System.out.println(arr[i]);
}
}
catch(InterruptedException e)
{
}
}
}
class Demojoin
{
public static void main(String args[])
{
System.out.println("The School Bus is waiting for the three children at the Bus Stop");
Demo ob1 = new Demo();
Thread t = new Thread(ob1);
t.start();
while(t.isAlive()) //Here you can make out the use of isAlive concept
{
try
{
System.out.println("Still waiting ........ ");
join(1000);
}
catch(InterrutptedException e)
{
}
}
System.out.println("Finally!!");
}
}
OUTPUT :

Join : This method is use to specify the time you want to wait for the specified thread to terminate .
Example :
class Demo
{
String arr[]={"Here comes the I'st child ",
"Here comes the II'nd child",
"Here comes the III'rd child"};
public void run()
{
try
{
for(int i=0;i<3;i++)
{
Thread.sleep(3000);
System.out.println(arr[i]);
}
}
catch(InterruptedException e)
{
}
}
}
class Demojoin
{
public static void main(String args[])
{
System.out.println("The School Bus is waiting for the three children at the Bus Stop");
Demo ob1 = new Demo();
Thread t = new Thread(ob1);
t.start();
while(t.isAlive()) //Here you can make out the use of isAlive concept
{
try
{
System.out.println("Still waiting ........ ");
join(1000);
}
catch(InterrutptedException e)
{
}
}
System.out.println("Finally!!");
}
}
OUTPUT :
No comments:
Post a Comment