Joining a thread
- join() waits for a thread to die
1. Syntax
- public void join()throws InterruptedException
- public void join(long milliseconds)throws InterruptedException
2. Example
public
class
join
extends
Thread{
public
void
run(){
for
(
int
i =
0
; i <
5
; i++){
try
{
Thread.sleep(
500
);
}
catch
(Exception e){
System.out.println(e);
}
System.out.println(i);
}
}
public
static
void
main(String[]args){
join t1 =
new
join();
join t2 =
new
join();
join t3 =
new
join();
t1.start();
try
{
t1.join();
}
catch
(Exception e){
System.out.println(e);
}
t2.start();
t3.start();
}
}
'Back-End > Java_1' 카테고리의 다른 글
[Java] Thread Priority (0) | 2016.10.07 |
---|---|
[Java] Naming Thread (0) | 2016.10.07 |
[Java] Call a run() directly instead start() (0) | 2016.10.07 |
[Java] Sleeping a thread (0) | 2016.10.07 |
[Java] Thread Scheduler (0) | 2016.10.07 |