where to use join method and explain with real time
senario?and programatical explenation also..
Answer Posted / ashwin khandelwal
class DemoAlive extends Thread {
int value;
public DemoAlive(String str){
super(str);
value=0;
start();
}
public void run(){
try{
while (value < 5){
System.out.println(getName() + ": " + (value++));
Thread.sleep(250);
}
} catch (Exception e) {}
System.out.println("Exit from thread: " + getName());
}
}
public class DemoJoin{
public static void main(String[] args){
DemoAlive da = new DemoAlive("Thread a");
DemoAlive db = new DemoAlive("Thread b");
try{
System.out.println("Wait for the child threads to finish.");
da.join();
if (!da.isAlive())
System.out.println("Thread A not alive.");
db.join();
if (!db.isAlive())
System.out.println("Thread B not alive.");
} catch (Exception e) { }
System.out.println("Exit from Main Thread.");
}
}
| Is This Answer Correct ? | 2 Yes | 0 No |
Post New Answer View All Answers
What is getclass () getname () in java?
What is difference between final and finally in java?
How can we pass argument to a function by reference instead of pass by value?
What are the differences between string and stringbuffer?
How many java versions are there?
What is the primitive type byte?
Why is it called a string?
Does a class inherit the constructors of its superclass in java programming?
What is the full form of jpeg?
If you are given the name of the function at run time how will you invoke the function?
What is string and example?
What is exception hierarchy in java?
What is the range of the short type?
Is string serializable in java?
Which list is sorted in java?