Java线程池使用

时间:2023-03-09 07:30:20
Java线程池使用

1.构造函数

public ThreadPoolExecutor(int corePoolSize,
int maximumPoolSize,
long keepAliveTime,
TimeUnit unit,
BlockingQueue<Runnable> workQueue,
ThreadFactory threadFactory)

corePoolSize -

maximumPoolSize - 线程池中允许的最大线程数

keepAliveTime - when the number of threads is greater than the core, this is the maximum time that excess idle threads will wait for new tasks before terminating.

unit - the time unit for the keepAliveTime argument

workQueue - 工作队列,当corePoolSize达到最大值时,提交的线程保存在工作队列

Factory - 创建线程的工程