yield && sleep && join

yield is just a suggestion to give up CPU for other threads, JVM may be not accept the suggestion. Not suggesting to use yield more than debug level.
sleep gets to let current thread give up CPU for other threads, JVM will executes its order as command.
join is to make current thread wait a sub-thread(or sub-threads) finishing running, and the current thread that invokes the sub-thread is blocked.

public class Main {
    public void main(String[] args){  
        Thread thread1 = new Thread();
        thread1.start();
        thread1.join();     // join
    }
}
// Then main thread will wait for thread1 finishing running, 
// then main thread starts to run again. 
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 餐酒搭配看似是一种科学,但实质上则更加贴近体验。上回我们说到鸡肉和葡萄酒的搭配,这次我们来聊一聊葡萄酒和鱼肉如何完...
    红酒说WineSay阅读 1,688评论 0 1
  • 我快记不清你的样子了,即使每天繁忙之余都会习惯的想你。我有些担忧,我的生命自从离开了你,他变的不开心,忧愁...
    可可小马阅读 4,251评论 0 0

友情链接更多精彩内容