线程池创建和提交线程(JDK1.8.0_181)
2021-11-14 23:16:36 0 举报
线程池创建和提交线程(JDK1.8.0_181)
作者其他创作
大纲/内容
workers.add
thread.start
创建普通线程
workerCount<corePoolSize
run()
afterExecute
thread=threadFactory.newThread(this)
构造函数-填充属性
new ThreadPoolExecutor
new Worker
keepAliveTime=5
maximumPoolSize=4
拒绝创建线程
ctl:封装workerCount和runState
handler.rejectedExecution
workQueue.offer(runnable)=False|| state != Running
入队列
workQueue.offer(runnable)=False workerCount>maximumPoolSize
默认属性
workQueue.offer
getTask()
提交线程
corePoolSize=2
beforeExecute
throw Exception
task.run
workQueue=new LinkedBlockingQueue<>(10)
forstTask=r
workers:线程池中所有线程的集合
线程池初始化
threadPoolExecutor.execute(() -> System.err.println(\"hello world\"));
unit=SECONDS
创建核心线程
threadFactory = Executors.defaultThreadFactory()
workQueue.offer(runnable) workerCount<corePoolSize
handler=new AbortPolicy()
setState(-1)
new Worker(r)
runWorker(w)
allowCoreThreadTimeOut:是否回收核心线程
0 条评论
下一页