标签:概述 exec ice cache getname adp executors 一个 线程
一 . 概述
我们知道线程的创建代价是比较大的,因此我们也可以引入池的概念,帮助实现资源重用的概念.
二 . 线程池的基本使用
public static void main(String[] args) { // 创建一个线程池 ExecutorService threadPool = Executors.newCachedThreadPool(); // 向线程池中加入任务 for (int i = 0; i < 10; i++) { threadPool.execute(() -> { System.out.println(Thread.currentThread().getName()); }); } //关闭线程池 threadPool.shutdown(); }
三 . 常用的线程池
CacheThreadPool : 带缓冲的线程池
fixThreadPool : 固定大小的线程池
Singloton : 单一线程的线程池.
四 .总结
这里只是简单的使用一下线程池而已,在后面会详细的分析一下线程池.
标签:概述 exec ice cache getname adp executors 一个 线程
原文地址:https://www.cnblogs.com/trekxu/p/8975358.html