开发者

Java Spring ThreadPoolExecutorFactoryBean

开发者 https://www.devze.com 2023-03-27 21:20 出处:网络
If I configure ThreadPoolExecutorFactoryBean with maxPoolSize=1 - so executor always has 1 thread - if I run 2 or 开发者_如何学Pythonmore threads - spring create some queue or next invocation will wai

If I configure ThreadPoolExecutorFactoryBean with maxPoolSize=1 - so executor always has 1 thread - if I run 2 or 开发者_如何学Pythonmore threads - spring create some queue or next invocation will wait previous? Thanks.


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

executor.execute(runnable1);
executor.execute(runnable2);

and runnable1 will be executed in the thread first, once that's finished, runnable2 will be executed.

0

精彩评论

暂无评论...
验证码 换一张
取 消