I'm using springs ThreadPoolTaskScheduler:
private ThreadPoolTaskScheduler taskScheduler;
public void initialize() {
taskScheduler = new ThreadPoolTaskScheduler();
taskScheduler.setPoolSize(50);
taskScheduler.initialize();
}
I then have several tasks (around 8, of which only 2 run every 2 Minutes, rest once a day), they will never exceed 50 threads at the same time.
ScheduledFuture<?> taskFuture = taskScheduler.schedule(ctr, ctr.getCronTrigger());
ctr is a class implementing Runnable. The run function in that class does have a @Async (unknowingly if this is problematic).
The problem is that after a while (usually several days or weeks) the taskScheduler will apparently be "full" and reject everything:
org.springframework.core.task.TaskRejectedException: Executor [java.util.concurrent.ThreadPoolExecutor@3f09fa69[Running, pool size = 2, active threads = 2, queued tasks = 100, completed tasks = 1961]] did not accept task: org.springframework.aop.interceptor.AsyncExecutionInterceptor$$Lambda$1322/0x0000000840bce440@47226288
Why is the pool size 2? I am not changing it anywhere. The above code is the only place in code where it's manipulated/set.
The above code is also the only place the taskScheduler is touched anywhere in code.
After having searched and tried everything, im unable to replicate this problem but it occassionally keeps happening. Maybe someone has a clue what it could be or can point me in a direction.
I greatly appreciate any help.
question from:
https://stackoverflow.com/questions/65846782/spring-threadpooltaskscheduler-pool-size-is-not-the-configured-one-taskrejecte 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…