where to use join method and explain with real time
senario?and programatical explenation also..



where to use join method and explain with real time senario?and programatical explenation also....

Answer / 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

More Core Java Interview Questions

Can an arraylist be empty?

0 Answers  


What is a newline character in java?

0 Answers  


When should a function throw an exception?

0 Answers   Thomson Reuters, Virtusa,


what is the use of abstract class and interface with example?

2 Answers   Cycore, DNS, Technoram,


how tha garbage collector know that the object will be deleted? on which algorithm the garbage collector works? what is the working principle of garbage collector? How manay types of garbage collectors r there?

1 Answers   HP, SparkTG,






What is the statements?

0 Answers  


What is a boolean in java?

0 Answers  


Explain about transient variables in java?

0 Answers  


What is volatile data type?

0 Answers  


How to pass arraylist to stored procedure in java?

0 Answers  


Can we override private methods?

0 Answers  


Define class?

0 Answers  


Categories