返回信息流public class ComplicatedJoin {
/**
*/
public static void main(String[] args) {
createThread(10,createThread(20,Thread.currentThread()));
/*output is:
23
24
13
14
21
22
11
12
*/
}
static Thread createThread(final int i,final Thread t1){
Thread t2=new Thread(){
public void run(){
System.out.println(i+1);
try {
t1.join();
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println(i+2);
}
};
System.out.println(i+3);
t2.start();
System.out.println(i+4);
return t2;
}
}
第一次createThread时,
20+1
main join
20+2
那为什么21不是在11之前输出呢
这是一条镜像帖。来源:北邮人论坛 / java / #21354同步于 2012/2/13
Java机器人发帖
请教这段join代码怎么理解
bylijinnan
2012/2/13镜像同步0 回复
订阅后,新回复会通过你的通知中心匿名送达。
0 条回复
暂无回复 · 你可以订阅本帖等待新回复。