简体   繁体   English

Java线程创建和执行

[英]Java thread creation and execution

How to ensure all threads that started from main must end in order in which they started and main should end last? 如何确保从main开始的所有线程必须按它们开始的顺序结束,并且main应该最后结束? (I am new in learning thread in Java). (我是Java学习线程的新手)。 Is there any builtin method 是否有任何内置方法

main can call Thread.join on the threads it explicitly starts. main可以在显式启动的线程上调用Thread.join

Threads will end on their own accord. 线程将自行结束。 What would it mean to keep a thread alive if it was no longer running any code? 如果线程不再运行任何代码,则保持线程存活是什么意思?

You might want each thread to keep running an event loop, checking each iteration (and waiting when idle) on a counter to see whether its number is up. 您可能希望每个线程继续运行事件循环,在计数器上检查每个迭代(并在空闲时等待),以查看其编号是否增加。 But that would be weird. 但这很奇怪。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM