现有三个线程T1,T2,T3 三个线程依次执行
2017-10-09 17:52
477 查看
直接上代码
package test; public class ThreadJoin { public static void main(String[] args) { thread3.start(); thread2.start(); thread1.start(); } static Thread thread1 = new Thread(new Runnable() { @Override public void run() { System.out.println("t1"); } }); static Thread thread2 = new Thread(new Runnable() { @Override public void run() { try { thread1.join(); } catch (InterruptedException e) { e.printStackTrace(); } System.out.println("t2"); } }); static Thread thread3 = new Thread(new Runnable() { @Override public void run() { try { thread2.join(); } catch (InterruptedException e) { e.printStackTrace(); } System.out.println("t3"); } }); }
执行结果
t1 t2 t3
thread的join方法其实底层就是调用的object的wait与notify机制
t2里面调用t1.join(),其实调用的是t1里面的wait方法
在t1执行完毕之后t1调用notify通知t2可以继续执行
下面是一个详细的连接
wait与notify
相关文章推荐
- 现有T1、T2、T3三个线程,你怎样保证T2在T1执行完成之后执行,T3在T2执行完后执行?
- 1.如果你有三个线程,分别为T1,T2,T3,如何让线程T2在线程T1之后执行,在线程T3之前执行。
- 有三个线程T1,T2,T3,下面方法可以确保它们按顺序执行的有()该线程继续执行
- 有三个线程T1 T2 T3,如何保证他们按顺序执行-转载
- 1)现在有T1、T2、T3三个线程,你怎样保证T2在T1执行完后执行,T3在T2执行完后执行?
- 有三个线程T1 T2 T3,如何保证他们按顺序执行
- 有三个线程T1 T2 T3,如何保证他们按顺序执行
- 现在有T1、T2、T3三个线程,怎样保证T2在T1执行完后执行,T3在T2执行完后执行
- 现在有T1、T2、T3三个线程,你怎样保证T2在T1执行完后执行,T3在T2执行完后执行
- 现在有T1、T2、T3三个线程,你怎样保证T2在T1执行完后执行,T3在T2执行完后执行
- 现在有T1、T2、T3三个线程,你怎样保证T2在T1执行完后执行,T3在T2执行完后执行?
- 1)现在有T1、T2、T3三个线程,你怎样保证T2在T1执行完后执行,T3在T2执行完后执行?
- 现在有T1、T2、T3三个线程,你怎样保证T2在T1执行完后执行,T3在T2执行完后执行?
- 有三个线程T1 T2 T3,如何保证他们按顺序执行
- 代码详解の使用CountDownLatch解决面试问题:T1和T2线程执行计算,T3线程计算结果的统计
- 实现T1线程执行后再执行T2线程,之后再执行T3线程
- 保证三个线程依次按顺序执行
- C#中添加三个线程同时启动执行某一方法,并依次调用某方法中的循环打印输。
- 三个线程按照顺序依次执行
- 三个线程依次顺序执行