package com.yyc.security; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; /** * @Auther: yangyongcui * @Date: 2018/8/22: 11:15 * @Description: */ public class ThreadTest implements Runnable { private String threadName; ThreadTest(String threadName) { this.threadName = threadName; } @Override public void run() { System.out.println(threadName + "执行中..."); } public static void main(String[] args) throws InterruptedException { ThreadTest t1 = new ThreadTest("t1"); Thread thread1 = new Thread(t1); thread1.start(); thread1.join(); ThreadTest t2 = new ThreadTest("t2"); Thread thread2 = new Thread(t2); thread2.start(); thread2.join(); ThreadTest t3 = new ThreadTest("t3"); Thread thread3 = new Thread(t3); thread3.start(); thread3.join(); //=================================第二种===================================== System.out.println("============================================="); ExecutorService executorService=Executors.newSingleThreadExecutor(); executorService.submit(t1); executorService.submit(t2); executorService.submit(t3); executorService.shutdown(); } }
如何保证线程线性执行
最新推荐文章于 2021-02-12 10:37:34 发布