Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
359 views
in Technique[技术] by (71.8m points)

java - Spring ThreadPoolTaskScheduler Pool size is not the configured one - TaskRejectedException

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...