Maximum pool size of `ScheduledThreadPoolExecutor` cannot be changedJAVA-W0012
It is not possible to change the max pool size of a ScheduledThreadPoolExecutor using the setter functions inherited from ThreadPoolExecutor.
From ScheduledThreadPoolExecutor's JavaDocs:
While
ScheduledThreadPoolExecutorinherits fromThreadPoolExecutor, a few of the inherited tuning methods are not useful for it. In particular, because it acts as a fixed-sized pool usingcorePoolSizethreads and an unbounded queue, adjustments tomaximumPoolSizehave no useful effect.
This may be contrary to assumptions the programmer may make, leading to subtle logic errors.
Bad Practice
ScheduledThreadPoolExecutor ste = new ScheduledThreadPoolExecutor(2);
ste.setMaximumPoolSize(4); // Doesn't work
Recommended
Check how ScheduledThreadPoolExecutor is used and rewrite the code to obviate the need to change the max pool size.
If it is possible to avoid the need to resize the thread pool, try that approach.