Spring5 ThreadPoolTask​​Executor产生`org.springframework.core.task.TaskRejectedException`“未接受任务”

时间:2020-06-10 05:58:33

标签: spring threadpoolexecutor

我正在使用org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor来执行批处理任务。 (春季软件包的版本为5.1.4.RELEASE

这个想法很简单

  • 具有固定数量的任务(例如10,000个)
  • 线程池具有(核心:10,最大:20,队列容量:20)
  • 有空间时将任务推入线程池

所以我写得像下面

public void test(){
    int start = 1, end = 10000;
    int cur = start;
    boolean jobLeft = true;
    while(jobLeft) {
        while(threadPoolTaskExecutor.getActiveCount() < maxThreadPool) {
            asyncAnnotationInstance.callMethod(cur);
            cur++;
            if(cur > end) {
                jobLeft = false;
            }
        }
    }
}

但是getActiveCount() < maxThreadPool语句以某种方式起作用。 我打印错误

org.springframework.core.task.TaskRejectedException: Executor [java.util.concurrent.ThreadPoolExecutor@6c773399[Running, pool size = 20, active threads = 20, queued tasks = 18, completed tasks = 471]] did not accept task: org.springframework.aop.interceptor.AsyncExecutionInterceptor$$Lambda$923/0x000000080076c440@5de11302

我想知道有任何错误,如果有,如何解决。

0 个答案:

没有答案