package ch03;
public class JoinTest extends Thread {
int start;
int end;
int total;
public JoinTest(int start, int end) {
this.start = start;
this.end = end;
}
@Override
public void run() {
int i;
for (i = start; i <= end; i++) {
total += i;
}
}// run을 쓰기위해 위에 변수 선언
public static void main(String[] args) {
JoinTest jt1 = new JoinTest(1, 50);//1~50
JoinTest jt2 = new JoinTest(51, 100); //51~100 더한값
jt1.start();
jt2.start();
//주최는 mainThread
try {
jt1.join();
jt2.join();
} catch (InterruptedException e) {
e.printStackTrace();
} //jt1 끝나면 jt2 끝나면 lastTotal값을 출력
//잘쓰이진않음
int lastTotal = jt1.total + jt2.total;
System.out.println("jt1.total = " +jt1.total);
System.out.println("jt2.total = " +jt2.total);
System.out.println("lastTotal = " + lastTotal);
}
}