我是线程世界的一个新手段,仍然在学习,因为我正在通过线程的概念并加入其他线程等待早期线程完成的概念,并从中加入结束,请你告诉我,我想启动三个线程T1,T2,T3,其中t2将在T1完成后启动。关于按顺序连接线程
0
A
回答
0
在一些线程完成后,可以使用障碍来启动某个动作(也许是另一个线程)。
检查:http://programmingexamples.wikidot.com/java-barrier了解更多信息。
但等待只有一个线程确实没有做出太大的意义......
2
要等到线程1是完全做得到,然后启动线程2我明白了什么,而线3可随处运行。简单的代码,我想满足你的问题:
Thread thread1 = new Thread1();
Thread thread2 = new Thread2();
Thread thread3 = new Thread3();
thread3.start();
thread1.start();
try {
thread1.join();
thread2.start();
} catch (InterruptedException e) {
//if you do not use thread1.interrupt() this will not happen.
}
0
做这样的事情:
Thread T1 = new Thread(new ThreadExm); // where ThreadExm implements Runnable
Thread T2 = new Thread(new ThreadExm);
try {
// Start the thread1 and waits for this thread to die before
// starting the thread2 thread.
T1.start();
T2.join();
// Start thread2 when T1 gets completed
thread2.start();
} catch (InterruptedException ex) {
ex.printStackTrace();
}
相关问题
- 1. 按顺序连接点
- 2. Java线程连接创建线程的顺序运行
- 3. 线程池是否按顺序运行?
- 4. WaitHandle.WaitAny允许线程按顺序输入
- 5. 多线程开始按顺序vb.net
- 6. 正在按顺序运行的线程
- 7. 线程未按顺序运行
- 8. 如何连接按特定顺序连接表中的值,mysql
- 9. 多线程启动和连接顺序的区别?
- 10. 线程和关于执行顺序的混淆
- 11. Java多线程套接字 - 如何按顺序发送响应
- 12. Python线程似乎按顺序运行线程
- 13. 如何在守护程序线程中关闭sqlite连接?
- 14. 关闭死线程上的ActiveRecord连接
- 15. 连接池有益于多线程Java程序
- 16. 内部连接的顺序
- 17. iTunes连接截图顺序
- 18. 连接的顺序更快?
- 19. 关于线程
- 20. 关于线程
- 21. 新程序不按顺序?
- 22. 关于JDBC连接
- 23. 关于多线程程序的查询
- 24. 在select_tag按字母顺序排序,在导轨连接表
- 25. 在sqlalchemy中外连接两个表时按顺序排序
- 26. BASH CURL:在请求之间不要关闭连接时按顺序运行
- 27. 关于远程sqlite数据库连接
- 28. boost ::线程执行顺序
- 29. QT线程,信号顺序
- 30. 套接字连接 - 消息顺序?
如果你只是想有一个线程运行的时间,何苦在所有创建三个线程? – 2013-02-18 17:03:19
我觉得还有T3。 – Vlad 2013-02-18 17:04:15
你可以在这里找到一个简单的解决方案:http://stackoverflow.com/a/13695190/469220 – Vlad 2013-02-18 17:05:34