How does pool size actually work with Spring's scheduled tasks?
java, scheduled-tasks, spring, threadpool
Solution
First of all `<task:scheduler/>` is a wrapper around `ScheduledThreadPoolExecutor` extending `ThreadPoolExecutor`. JavaDoc for the latter says:
even core threads are initially created and started only when new tasks arrive
Secondly you must understand that scheduled tasks (this is a Java feature, not Spring's) do not run concurrently, even if they take longer time than repeat interval. They simply wait. So you don't have 15 events waiting in the queue, you have 15 executions that are late and wait for that single thread. No need to create another one because next execution has to wait for the previous one to finish. Again, this is how Java scheduling framework works.
Of course if you have several different tasks scheduled, more threads will be created.
Problem
I have a task scheduled as such: ``` <task:scheduler id="notification.scheduler" pool-size="15" /> <task:scheduled-tasks scheduler="notification.scheduler"> <task:scheduled ref="notificationProcessor" method="sendNextQueueEvent" fixed-rate="500" /> <task:scheduled ref="notificationProcessor" method="deleteNextCompletedEvent" fixed-rate="60000" /> </task:scheduled-tasks> ``` I think I have a misunderstanding of how the scheduled tasks work with the pool size. Despite the pool-size being 15, it seems only one thread is being used. For example, if I have fifteen events in the queue, I would think there would be fifteen threads checking every minute to remove an event from the queue. Obviously, this is wrong. How can I make it so that there's fifteen threads calling this method for the time interval using Spring's scheduler abstraction? Edit: What I want to accomplish is this: Every half second, I want to check to see if there are queued events to send. When this is done, I want to send a maximum of 15 (if 15 exist). How would I accomplish this using the spring abstractions for the java thread stuff?