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

Is there a jre for java 11?

0 Answers  


What is lossy conversion in java?

0 Answers  


Can we execute a program without main?

0 Answers  


What are the java ide’s?

0 Answers  


What is the purpose of extern variable?

0 Answers  






What is the return type of read()?

3 Answers  


what is the Use of throws exception?

2 Answers  


Is minecraft 1.15 out?

0 Answers  


What is array in java?

0 Answers  


Java is Pass by Value or Pass by Reference?

0 Answers   BirlaSoft,


Explain the importance of thread scheduler in java?

0 Answers  


What is left shift and right shift?

1 Answers  


Categories