java - ThreadPoolExecutor.execute()方法疑惑
ringa_lee
ringa_lee 2017-04-18 09:35:56
0
2
792

根据类的继承机构,我们知道ThreadPoolExecutorService 继承了AbstractExecutorService类继承了ExecutorService接口继承了Executor接口中的execute()方法,这个方法是被用来专门执行异步任务的,通过传入参数Runnable来执行的。但是我看到ThreadPoolExecutorService.execute(Runnable command)方法中的源码表示不理解,求大牛帮忙看看这个源码,究竟都做了一些什么?

ringa_lee
ringa_lee

ringa_lee

reply all(2)
阿神
  1. If there are threads smaller than corePoolSize (core thread) executing, the current task will be submitted to the first place. Then the addWorker method will do some checks;

  2. When a new task is put into the queue, it will be checked again (because the status will change or the thread pool is closed) to determine whether it needs to be rolled back or a new thread object needs to be created;

  3. If the task cannot be put into the queue, it will try to add a new Thread object, otherwise the task will be rejected

PS: I remember reading a very good article that analyzed this method and the entire thread pool knowledge in detail. Let me help you find it...

update: In-depth understanding of Java thread pool

左手右手慢动作

Come on

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template