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 dynamic array in java?
what is the purpose of using rmisecuritymanager in rmi?
Why is java so popular?
What is the static method?
What are the 3 types of control structures?
Can we create an object if a class doesn't have any constructor ( not even the default provided by constructor ) ?
What is the char data type?
What is ++ a in java?
What is the difference between preemptive scheduling and time slicing in java programming?
Can we sort set in java?
Can we serialize static variables in java?
Why call by value prevents parameter value change?
What is the purpose of stub and skeleton?
Considering notepad/ie or any other thing as process, what will happen if you start notepad or ie 3 times? Where 3 processes are started or 3 threads are started?
Is array dynamic in java?