public class Joining{
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) {
}
System.out.println(i+2);
}
};
System.out.println(i+3);
t2.start();
System.out.println(i+4);
return t2;
}
public static void main(String[] args) {
createThread(10,createThread(20,Thread.currentThread()));
}
}
这个程序难吗,有多少人能看出答案来,看出来的讲解一下列!
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) {
}
System.out.println(i+2);
}
};
System.out.println(i+3);
t2.start();
System.out.println(i+4);
return t2;
}
public static void main(String[] args) {
createThread(10,createThread(20,Thread.currentThread()));
}
}
这个程序难吗,有多少人能看出答案来,看出来的讲解一下列!
解决方案 »
- 怎么使用Java读取Google搜索结果的网页?
- dom操作xml文档时候出现的编码问题,在线等,解决了结贴~~~~
- 软件验收会 专家会大概提些什么问题?
- 一个比较棘手的字符串处理,解决就给分
- JAVA都说用在企业开发,服务器端,那到底应用在什么地方呢?
- 简单问题,会的请说!!
- 我如何才能取到系统的时间呢?请手们指点。
- 急!!!哪位知道用JAVA编的两个物体碰撞的3D动画例子怎样可以找到!!!多谢!
- 在看书、看资料的时候总看到“服务框架”这个词汇,我对该词不太理解,谁能解释一下?
- 请有没人做过异构系统整合的?如果java要和PB,Excel或是VB做的东西交互,应该怎么办,我头都想破了,请高手指点一下!
- java中如何求两个日期之间的天数?
- swt程序的导出
Thread t2 = new Thread() { public void run() {
System.out.println(Thread.currentThread().getName() + ":" + (i + 1));
try {
t1.join();
} catch (InterruptedException e) {
}
System.out.println(Thread.currentThread().getName() + ":" + (i + 2));
}
};
System.out.println(Thread.currentThread().getName() + ":" + (i + 3));
t2.start();
System.out.println(Thread.currentThread().getName() + ":" + (i + 4));
return t2;
} public static void main(String[] args) {
createThread(10, createThread(20, Thread.currentThread()));
}
} 这样改一下,再单步调试一下,可以观察每一步中每个线程的状态,应该很容易明白了.