Package | Description |
---|---|
cn.hutool.core.thread |
提供线程及高并发封装,入口为ThreadUtil
|
Modifier and Type | Method and Description |
---|---|
static ExecutorBuilder |
ExecutorBuilder.create()
创建ExecutorBuilder,开始构建
|
ExecutorBuilder |
ExecutorBuilder.setAllowCoreThreadTimeOut(boolean allowCoreThreadTimeOut)
设置线程执行超时后是否回收线程
|
ExecutorBuilder |
ExecutorBuilder.setCorePoolSize(int corePoolSize)
设置初始池大小,默认0
|
ExecutorBuilder |
ExecutorBuilder.setHandler(RejectedExecutionHandler handler)
设置当线程阻塞(block)时的异常处理器,所谓线程阻塞即线程池和等待队列已满,无法处理线程时采取的策略
此处可以使用JDK预定义的几种策略,见
RejectPolicy 枚举 |
ExecutorBuilder |
ExecutorBuilder.setKeepAliveTime(long keepAliveTime)
设置线程存活时间,即当池中线程多于初始大小时,多出的线程保留的时长,单位纳秒
|
ExecutorBuilder |
ExecutorBuilder.setKeepAliveTime(long keepAliveTime,
TimeUnit unit)
设置线程存活时间,即当池中线程多于初始大小时,多出的线程保留的时长
|
ExecutorBuilder |
ExecutorBuilder.setMaxPoolSize(int maxPoolSize)
设置最大池大小(允许同时执行的最大线程数)
|
ExecutorBuilder |
ExecutorBuilder.setThreadFactory(ThreadFactory threadFactory)
设置线程工厂,用于自定义线程创建
|
ExecutorBuilder |
ExecutorBuilder.setWorkQueue(BlockingQueue<Runnable> workQueue)
设置队列,用于存在未执行的线程
可选队列有: 1. |
ExecutorBuilder |
ExecutorBuilder.useArrayBlockingQueue(int capacity)
使用
ArrayBlockingQueue 做为等待队列有界队列,相对无界队列有利于控制队列大小,队列满时,运行线程小于maxPoolSize时会创建新线程,否则触发异常策略 |
ExecutorBuilder |
ExecutorBuilder.useSynchronousQueue()
使用
SynchronousQueue 做为等待队列(非公平策略)它将任务直接提交给线程而不保持它们。 |
ExecutorBuilder |
ExecutorBuilder.useSynchronousQueue(boolean fair)
使用
SynchronousQueue 做为等待队列它将任务直接提交给线程而不保持它们。 |
Copyright © 2024. All rights reserved.