多线程知识
企业开发
2018-05-09 16:50:38
阅读次数: 1
- T1,T2,T3三个线程工作顺序,按照T1,T2,T3依次进行
- public class T1 implements Runnable{
-
- @Override
- public void run() {
- try {
- System.out.println("T1开始工作.....");
- Thread.sleep(RandomUtils.nextInt(300));
- System.out.println("T1结束工作>>>>>");
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
-
- }
- public class Main {
-
- public static void main(String[] args) throws InterruptedException {
-
- Thread t1 = new Thread(new T1());
- Thread t2 = new Thread(new T2());
- Thread t3 = new Thread(new T3());
-
- t1.start();
- t1.join();
-
- t2.start();
- t2.join();
-
- t3.start();
- t3.join();
-
- System.out.println("T1、T2、T3依次工作结束.");
- }
-
- }
- 加入join方法之后T1,T2,T3不再是无序的线程,按照T1,T2,T3顺序执行了。
转载自cuishikuan.iteye.com/blog/2225144