import java.util.*;
public class ThreadJoin2 implements Runnable {
public void run() {
for( int i=1 ; i<10 ; i++ ) {
System.out.println( Thread.currentThread().getName() + " : " + i +
" : " + new Date().toString() );
}
}
public static void main( String[] args ) {
ThreadJoin2 ts = new ThreadJoin2();
// 두개의 Thread 생성
Thread first = new Thread( ts, "first" );
Thread second = new Thread( ts, "second" );
first.start();
// first thread의 join() 호출
try {
first.join();
} catch ( InterruptedException ie ) {
System.out.println( ie.toString() );
}
second.start();
// main thread의 마지막 명령문
System.out.println( "main thread end" );
}
}
'새로워지기 > 서른의 생활코딩' 카테고리의 다른 글
ex12) java_thread (0) | 2012.03.04 |
---|---|
ex11) java_thread (0) | 2012.03.04 |
ex9) java_thread (0) | 2012.03.04 |
ex8) java_thread (0) | 2012.03.04 |
ex7) java_thread (0) | 2012.03.04 |
댓글