线程池java,java创建全局的线程池,java线程池之一:创建线程池的方法
在Java开发过程中经常需要用到线程,为了减少资源的开销,提高系统性能,Java提供了线程池,即事先创建好线程,如果需要使用从池中取即可,Java中创建线程池有以下的方式,
1、使用ThreadPoolExecutor类
2、使用Executors类
其实这两种方式在本质上是一种方式,都是通过ThreadPoolExecutor类的方式,下面分析其使用方式。
一、ThreadPoolExecutor的方式
1、使用方法
查看JDK的源码,ThreadPoolExecutor类提供了以下构造方法,
可以看到有四个构造方法,先看第一个构造方法,其代码如下,
public ThreadPoolExecutor(int corePoolSize,
int maximumPoolSize,
long keepAliveTime,
TimeUnit unit,
Blocking