首页 > 编程语言 > 详细

控制多线程执行顺序

时间:2018-12-01 14:44:15      阅读:210      评论:0      收藏:0      [点我收藏+]

虽然项目用不上,先备份吧,控制多线程执行顺序有两种方法

1.通过join方法保证多线程的顺序性的特性

join:让主线程等待子线程结束后才能继续执行

public  static void main(String[] args) throws InterrupterException
{
    thread1.start();
    thread1.join();
    thread2.start();
    thread2.join();
    thread3.star();
}

2.
ExcutorService executor = Excutors.newSingleTheadExcutor():FIFO

static ExcutorService excutorService = Excutors.newSingleTheadExcutor();
public  static void main(String[] args) throws InterrupterException
{
    excutorService.submit(thread1);
    excutorService.submit(thread2);
    excutorService.submit(thread3);
}

 

控制多线程执行顺序

原文:https://www.cnblogs.com/CuiHongYu/p/10048970.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!