user710818
user710818

Reputation: 24248

Java Spring ThreadPoolExecutorFactoryBean

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.

Upvotes: 0

Views: 1108

Answers (1)

beny23
beny23

Reputation: 35008

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.

Upvotes: 2

Related Questions