newFixedThreadPool固定线程使用

1.newFixedThreadPool固定线程池,  使用完毕必须手动关闭线程池, 否则会一直在内存中存在,

 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.newFixedThreadPool(4);
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         }
23     }
24     
25 }
原文地址:https://www.cnblogs.com/redhat0019/p/8065937.html