I tried to look through the OpenJDK source code. What I think I found out is the following:
- There are
coreSize
threads in the thread pool ScheduledThreadPoolExecutor
has an internal queue (DelayedWorkQueue
) which is similar to a priority queue- The internal queue has an additional thread object, called
leader
What I don't fully understand is how the ScheduledThreadPoolExecutor
does the actual scheduling. Does the leader repeatedly peek at the queue if the delay for the first entry is over? Or is the thread actually put to sleep and wait for any kind of wake up from somewhere?
Also, if all threads in the pool are currently busy and the next task should be scheduled, it is delayed. Is there a common way to find out if a task was delayed?