Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

关于 线程池中你不容错过的一些细节 的疑问 #160

Open
luryson opened this issue May 25, 2019 · 0 comments
Open

关于 线程池中你不容错过的一些细节 的疑问 #160

luryson opened this issue May 25, 2019 · 0 comments

Comments

@luryson
Copy link

luryson commented May 25, 2019

https://github.com/crossoverJie/JCSprout/blob/master/docs/thread/thread-gone2.md

这篇文章比较详细的描述了线程池的工作流程,但是有一点需要指出:

image
这里的描述感觉有点误导,线程池中并发的实际是Worker。
image
我们在不但向线程池中提交任务的时候,线程池根据配置,不断生成新的Worker或者将任务放到队列中,而新生成的Worker是用Thread封装后,执行了start()方法。而Worker的任务是执行分配的Runnable或者从队列中pool新提交的Runnable来进行执行,所以调用的是Runnable的run方法。(ps: start 是 Thread的方法,并非Runnable的方法)

所以关于这个问题的一个简单解释就是: 异常导致Worker退出,同时已提交的Runnable也不存在了,所以由线程池保证新生成的Worker并不能从队列中获取新的任务而一直处于等待状态。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant