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


Please Help Members By Posting Answers For Below Questions

What is linkedlist in java?

757


What is the difference between JVM and JRE?

846


Explain the polymorphism principle?

808


what is meant by encapsulation?

872


What is a wrapper method?

792


Explain with example the concept of constant variable in java.

908


What is arraylist e in java?

769


How to solve the problem of generating the unique hash keys with hash function?

1700


Difference between error and exception

5523


What are the 4 versions of java?

892


Why string is not thread safe?

793


What is java english?

709


what are abstract functions?

796


What are the two ways to create a thread?

774


How do you decide when to use arraylist and linkedlist?

771