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 implicit object in java?
What is meant by the value of a variable?
Is java still necessary?
What is the range of the short type?
How would you format a date in java? I.e. In the ddmmyyy format?
Is java call by reference?
Can vector have duplicates in java?
How to create a thread in java?
Give me an example of array and linked list? Where they can be used?
What is the purpose of default constructor?
What is the equal sign?
What is r in java?
What is string literal in java?
How will you initialize an Applet?
What is method reference?