본문 바로가기

콩's EDUCATION/콩's JAVA_RUN

Join

Join 예제


 

class Test extends Thread{
 int i=1;
 public void run(){
  try {
   sleep(5000); // 5초 일시중지
  } catch (InterruptedException e) {
   e.printStackTrace();
  }
  i=10;
  System.out.println("run : "+i);
 }
}
public class JoinTest {
 public static void main(String[] args) throws InterruptedException {
 Test t = new Test(); // 실행상태 ; main 생성상태
 t.start(); // 대기상태 ; t 실행상태 ; main
 // run 수행 완료 i 값: t 수행
 t.join(); // 실행상태  ; t 일시 정지 상태 ; main
 System.out.println("main= "+t.i);
 // t 아직도 대기중 , run 메소드 수행
 } // main
}

 

 

JoinTest.java