package test;
public class JoinTest {
/**
*
* @author Administrator/2012-3-1/上午09:50:15
*/
public static void main(String[] args) {
int threadNumber = 10;
for (int i = 0; i < threadNumber; i++) {
final int threadID = i;
Thread thread = new Thread() {
public void run() {
try {
Thread.sleep((long) (Math.random() * 10000));
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println(String.format("threadID:[%s] finished!!", threadID));
}
};
thread.start();
try {
thread.join();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
System.out.println("main thread finished!!");
}
}
注意: 通过join方法调用子线程是串行到主线程,不是并发