join() 최종 입니다. 스레드 메소드 다른 스레드가 끝날 때까지 스레드가 실행을 시작하지 않도록 스레드 실행 시작을 다른 스레드 실행 끝에 결합하는 데 사용할 수 있습니다. join() 메서드가 스레드 인스턴스에서 호출되면 현재 실행 중인 스레드는 스레드 인스턴스의 실행이 완료될 때까지 차단됩니다.
구문
public final void join() throws InterruptedException
예시
public class JoinTest extends Thread {
public void run() {
for(int i=1; i <= 3; i++) {
try {
Thread.sleep(1000);
} catch(Exception e) {
System.out.println(e);
}
System.out.println("TutorialsPoint "+ i);
}
}
public static void main(String args[]) {
JoinTest t1 = new JoinTest();
JoinTest t2 = new JoinTest();
JoinTest t3 = new JoinTest();
t1.start();
try {
t1.join(); // calling join() method
} catch(Exception e) {
System.out.println(e);
}
t2.start();
t3.start();
}
} 출력
TutorialsPoint 1 TutorialsPoint 2 TutorialsPoint 3 TutorialsPoint 1 TutorialsPoint 1 TutorialsPoint 2 TutorialsPoint 2 TutorialsPoint 3 TutorialsPoint 3