线程池 thread pool (线程池状态及线程维护策略; 线程池任务添加及运行流程)
2020-10-16 09:59:06 0 举报
线程池 thread pool (线程池状态及线程维护策略; 线程池任务添加及运行流程)
作者其他创作
大纲/内容
bit
run task
1
less thancorePoolSize
wait
yes
new a worker with task and start worker thread
0
recheck the state of pool
add into worker queue
end
......
check state of pool
got a task
add worker
not running
decrease wc by cas
checkif worker count is 0
core
TIDYING state2 << COUNT_BITS( 29 bits)
if wc greater than corePoolSize
keep this thread alive for core thread
add worker count(wc) by cas
get worker count(wc) from ctl
no
high 3 bits(state of the pool)
check worker count
STOP state1 << COUNT_BITS( 29 bits)
low 29 bits(worker count(wc) in the pool)
do reject strategy
state and storage strategy in thread pool
process of task add and task run in thread pool
check if current thread is not core
execute
runWorker
running
get task from queue by font color=\"#ff8000\
ctl (AtomicInteger)Integer.SIZE( 32 bits )
if task is null
task is null
TERMINATED state3 << COUNT_BITS( 29 bits)
gc this thread after got a task and handled or got null
looptry to get task from queue
do some pool check
Original ctl
queue empty
loop if task is not null or get a task from queue
do some post operation
RUNNING state-1 << COUNT_BITS( 29 bits)
SHUTDOWN state0 << COUNT_BITS( 29 bits)
0 条评论
下一页