Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SimpleAsyncTaskExecutor not releasing threads

I am running several spring batch partitioning jobs from within the same JVM instance. Each is configured to use 3 threads but every time a new job starts I see in the logs that SimpleAsyncTaskExecutor keeps increasing its thread number.

so first jobs shows:

09:53:02.370 [SimpleAsyncTaskExecutor-1] INFO...
09:53:02.370 [SimpleAsyncTaskExecutor-2] INFO...

and next jobs shows:

09:53:02.370 [SimpleAsyncTaskExecutor-3] INFO...
09:53:02.370 [SimpleAsyncTaskExecutor-4] INFO...

I would have expected each new job to use threads 1 and 2 and not create new ones...I am shutting down the job each time but can post code if needed.

like image 225
Christopher Richard Dobbs Avatar asked Dec 04 '25 14:12

Christopher Richard Dobbs


1 Answers

SimpleAsyncTaskExecutor does not reuse threads. Furthermore SimpleAsyncTaskExecutor by default creates unlimited threads.

For reuse threads you need to use ThreadPoolTaskExecutor.

Read below for more information:

https://egkatzioura.com/2017/10/25/spring-and-threads-taskexecutor/

https://egkatzioura.com/2017/10/25/spring-and-async/

https://egkatzioura.com/2017/10/25/spring-and-threads-transactions/

How to control the number of parallel Spring Batch jobs

like image 65
user2051896 Avatar answered Dec 06 '25 05:12

user2051896



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!