반응형
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
}
반응형
'콩's EDUCATION > 콩's JAVA_RUN' 카테고리의 다른 글
wait(), notify() (0) | 2014.05.21 |
---|---|
synchronized 연습 (0) | 2014.05.21 |
Runnable (0) | 2014.05.21 |
스레드(Thread) (0) | 2014.05.21 |
Java 문제 7 (0) | 2014.05.20 |