package thread.thread3;
public class JoinTest extends Thread {
private static Integer num = 0;
public static void main(String[] args) throws InterruptedException {
JoinTest thread = new JoinTest();
thread.start();
//join 等当前线程执行完后才开始执行其他线程
thread.join();
System.out.println("num" + num);
}
@Override
public void run() {
for (int i = 0; i < 5; i++) {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println(num++);
}
}
}
public class JoinTest extends Thread {
private static Integer num = 0;
public static void main(String[] args) throws InterruptedException {
JoinTest thread = new JoinTest();
thread.start();
//join 等当前线程执行完后才开始执行其他线程
thread.join();
System.out.println("num" + num);
}
@Override
public void run() {
for (int i = 0; i < 5; i++) {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println(num++);
}
}
}