package japan.example.test;
public class ThreadJoinTest {
public static void main(String[] args) throws InterruptedException {
new ThreadJoinTest().test();
}
public void test() throws InterruptedException {
Thread[] tt = new Thread[100];
for (int i = 0; i < tt.length; i++) {
tt[i] = new Thread(new ThreadJoin(i == 0 ? null : tt[i - 1]));
}
for (int i = 0; i < tt.length; i++) {
tt[i].start();
}
Thread.sleep(1000);
}
}
class ThreadJoin implements Runnable {
Thread t;
ThreadJoin(Thread t) {
this.t = t;
}
@Override
public void run() {
try {
if (t != null) {
t.join();
}
String name = Thread.currentThread().getName();
System.err.println("name|{}" + name);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}