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
what is thread? What are the high-level thread states? : Java thread
What is array initialization in java?
What is comparator in java?
What type of variable is error flag?
What is thread start?
What is difference between protected and private?
Why is singleton instance static?
What is the purpose of default constructor?
Should a main method be compulsorily declared in all java classes?
What is the difference between this() and super() in java?
What are streams?
do I need to use synchronized on setvalue(int)? : Java thread
Is simpledateformat safe to use in the multithreaded program?
what is server side caching?
How do I write a self declaration?