package com.zhangxueliang.demo.springbootdemo.JUC.c_026_01_ThreadPool;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

/**
 * @ProjectName springbootdemo_src
 * @ClassName T08_CachedPool
 * @Desicription TODO
 * @Author Zhang Xueliang
 * @Date 2019/12/5 19:46
 * @Version 1.0
 **/
public class T08_CachedPool {

    public static void main(String[] args) {
        ExecutorService executorService = Executors.newCachedThreadPool();
        for (int i = 0; i < 5; i++) {
            final int j=i;
            executorService.submit(()->{
                try {
                    TimeUnit.MILLISECONDS.sleep(50);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(Thread.currentThread().getName()+" "+j);
            });
        }
        System.out.println(executorService);

    }

}

Executors.newCachedThreadPool()使用示例_java