Thread Join() method
The
join() method waits for a thread to die. In other words, it causes the
currently running threads to stop executing until the thread it joins with
completes its task.
Fig: Join () Method |
Syntax:
public void join()throws InterruptedException
|
public void join(long milliseconds)throws
InterruptedException
|
Example of join() method
class TestJoinMethod1 extends Thread{
public void run(){
for(int i=1;i<=5;i++){
try{
Thread.sleep(500);
}
catch(Exception e){System.out.println(e);}
System.out.println(i);
}
}
No comments:
Post a Comment