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()使用示例
原创a772304419 ©著作权
©著作权归作者所有:来自51CTO博客作者a772304419的原创作品,请联系作者获取转载授权,否则将追究法律责任
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章