Java Spring ThreadPoolExecutorFactoryBean
如果我使用 maxPoolSize=1 配置 ThreadPoolExecutorFactoryBean - 那么执行器总是有 1 个线程 - 如果我运行 2 个或更多线程 - spring 创建一些队列或下一个调用将等待之前? 谢谢。
If I configure ThreadPoolExecutorFactoryBean with maxPoolSize=1 - so executor always has 1 thread - if I run 2 or more threads - spring create some queue or next invocation will wait previous?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果maxPoolSize为1,那么同时只会运行一个线程,因此同时只会执行一个任务。但是, ThreadPoolExecutor 有一个队列,因此当线程可用时,任何未立即执行的任务都将异步完成。
所以当你有一个maxPoolSize为1的ThreadPoolExecutor时,下面的代码将立即返回
,并且runnable1将首先在线程中执行,一旦完成,runnable2将被执行。
If the maxPoolSize is 1, then only one thread will run at the same time, so only one task will be executed at the same time. However, the ThreadPoolExecutor has a queue, so any tasks that are not executed immediately will be done asynchronously when a thread becomes available.
So when you have an ThreadPoolExecutor with maxPoolSize 1, the following code will return immediately
and runnable1 will be executed in the thread first, once that's finished, runnable2 will be executed.