threadPoolExecutor.execute();
public void execute(Runnable command) {
throw new NullPointerException();
* 1. If fewer than corePoolSize threads are running, try to
* start a new thread with the given command as its first
* task. The call to addWorker atomically checks runState and
* workerCount, and so prevents false alarms that would add
* threads when it shouldn't, by returning false.
* 2. If a task can be successfully queued, then we still need
* to double-check whether we should have added a thread
* (because existing ones died since last checking) or that
* the pool shut down since entry into this method. So we
* recheck state and if necessary roll back the enqueuing if
* stopped, or start a new thread if there are none.
* 3. If we cannot queue task, then we try to add a new
* thread. If it fails, we know we are shut down or saturated
* and so reject the task.
//workerCountOf(c)获取工作线程个数是否小于核心线程数
if (workerCountOf(c) < corePoolSize) {
//增加addWorker(command, true) 增加addWorker 第二个线程数是否核心
if (addWorker(command, true))
//如果大于核心线程数,判断是否运行,队列放入command
if (isRunning(c) && workQueue.offer(command)) {
没有运行线程,且可以进行队列出队列,执行拒绝策略(因为上次检查后已有的死亡)
if (!isRunning(recheck) && remove(command))
else if (workerCountOf(recheck) == 0)
else if (!addWorker(command, false))