자바 스레드 join() 메서드는 다소 혼란 스럽습니다. 나는 어떤 순서에서 스레드가 종료됩니다 예를join() 메서드 예제 이해
class MyThread extends Thread {
private String name;
private int sleepTime;
private Thread waitsFor;
MyThread(String name, int stime, Thread wa) { … }
public void run() {
System.out.print("["+name+" ");
try { Thread.sleep(sleepTime); }
catch(InterruptedException ie) { }
System.out.print(name+"? ");
if (!(waitsFor == null))
try { waitsFor.join(); }
catch(InterruptedException ie) { }
System.out.print(name+"] ");
그리고
public class JoinTest2 {
public static void main (String [] args) {
Thread t1 = new MyThread("1",1000,null);
Thread t2 = new MyThread("2",4000,t1);
Thread t3 = new MyThread("3",600,t2);
Thread t4 = new MyThread("4",500,t3);
t1.start();
t2.start();
t3.start();
t4.start();
}
}
을 다음습니까?
이것은 까다로운 질문입니까? 아니면 숙제? :) – bzlm
그냥 일부 전자 서적을 읽고 그 예제를 발견, 실제로 실행 스레드가 조인이 끝나기 위해 호출 된 스레드를 기다립니다, 어쩌면 내가 오늘 종료 : D –
스레드가 죽을 때까지 기다립니다. http://download.oracle.com/javase/1.4.2/docs/api/java/lang/Thread.html#join() –