Thread pool diagram
@startuml
note top of Executor : 线程池底层执行方法.Runnable
interface Executor {
~ void execute(Runnable command)
}
note top of ExecutorService : 通用方法
interface ExecutorService extends Executor{
~ void shutdown()
~ <T> Future<T> submit(Runnable task, T result);
}
note top of AbstractExecutorService : abstract通用方法:基本都是ExecutorService的实现
abstract AbstractExecutorService implements ExecutorService{
# RunnableFuture<T> newTaskFor(Runnable runnable, T value)
}
note top of ThreadPoolExecutor : 线程池参数的基本设置,并且泛化的执行任务 .execute(),corePoolSize:核心线程数,maximumPoolSize:最大可容纳线程数,keepAliveTime: 线程存活时长 TimeUnit:存活时间的单位刻度 workQueue:队列 threadFactory:实例化工厂 handler:拒绝策略
class ThreadPoolExecutor extends AbstractExecutorService{
- threadFactory
- handler
- keepAliveTime
- allowCoreThreadTimeOut
- corePoolSize
- maximumPoolSize
+ ThreadPoolExecutor(int corePoolSize,int maximumPoolSize,long keepAliveTime,TimeUnit unit,BlockingQueue<Runnable> workQueue,ThreadFactory threadFactory,RejectedExecutionHandler handler)
+ void execute(Runnable command)
}
ThreadPoolExecutor +-- Worker
class Worker extends AbstractQueuedSynchronizer implements Runnable{
}
interface Runnable{}
abstract AbstractQueuedSynchronizer{}
ThreadPoolExecutor +-- BlockingQueue
class ArrayBlockingQueue implements BlockingQueue{}
class LinkedBlockingQueue implements BlockingQueue{}
class SynchronousQueue implements BlockingQueue{}
class PriorityBlockingQueue implements BlockingQueue{}
class DelayQueue implements BlockingQueue{}
interface BlockingQueue extends Queue{}
interface Queue{}
ThreadPoolExecutor +-- RejectedExecutionHandler
interface RejectedExecutionHandler{}
class AbortPolicy implements RejectedExecutionHandler{}
class RejectHandler implements RejectedExecutionHandler{}
class DiscardPolicy implements RejectedExecutionHandler{}
class DiscardOldestPolicy implements RejectedExecutionHandler{}
class CallerRunsPolicy implements RejectedExecutionHandler{}
@enduml