(原创)JAVA多线程二线程池

一,线程池的介绍

线程池包括一下三种:

线程池名称 创建方法 特点 其他
固定大小线程池 ExecutorService threadpool = Executors.newFixedThreadPool(3) 大小固定  
缓存线程池 ExecutorService threadpool = Executors.newCachedThreadPool(); 大小不固定,随线程数量多而多  
单一线程池 ExecutorService threadpool = Executors.newSingleThreadExecutor(); 单一线程  

给线程池新增线程都是

threadpool.execute(new Runnable(){@oeveride run方法});

这个可以对比一下tomcat服务器原理来理解这个过程

关闭线程池

shutdown,等线程池的线程都结束了,就关闭线程池

shutdownnow,立马关闭线程池

二,线程池的数据:共享

原文地址:https://www.cnblogs.com/ningheshutong/p/5837662.html