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

How many bits are used to represent unicode, ascii, utf-16, and utf-8 characters?

834


Does anyone still use java?

850


What is a java string?

733


What is the meaning of I ++ in java?

859


What is object-oriented paradigm?

836


What is an object's lock and which object's have locks in java programming?

790


What does this mean java?

796


What is the benefit of using enum to declare a constant?

870


How many ways can an argument be passed to a subroutine and explain them?

795


What is a class reference?

777


What is scope of a variable?

838


Why does java doesnt suuport unsigned values?

1992


What does replaceall do in java?

700


Which collection is best for sorting in java?

899


Is 0 true or false?

722