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 is a boolean?

612


Explain the difference between treeset and treemap in java?

516


What is boolean used for?

582


What does exp mean in math?

522


Can a source file contain more than one class declaration?

502






What is the difference between abstract class and interface1? What is an interface?

549


What is implicit object in java?

538


Which package is always imported by default?

537


What is the disadvantage of synchronization?

547


What are the differences between include directive and include action?

534


How do I compare two strings in word in java?

530


Where can I find jdk in my computer?

457


Can we make main() thread as daemon?

566


Define an abstract class with reference to java.

566


Can we override constructors in java?

668