1.newSingleThreadExecutor单任务线程池, 一次只执行一个任务
1 package ThreadTest; 2 3 import java.util.concurrent.ExecutorService; 4 import java.util.concurrent.Executors; 5 6 public class Demo01 { 7 public static void main(String[] args) { 8 MyThread myThread = new MyThread(); 9 ExecutorService pool = Executors.newSingleThreadExecutor(); 10 for(int i=0; i<40; i++) { 11 pool.execute(myThread); 12 } 13 pool.shutdown(); 14 } 15 } 16 17 class MyThread implements Runnable{ 18 @Override 19 public void run() { 20 for(int i=0; i<30; i++) { 21 System.out.println(Thread.currentThread().getName()); 22 System.out.println("======================"); 23 System.out.println(); 24 } 25 } 26 27 }