首页 新闻 会员 周边 捐助

线程池异常:.RejectedExecutionException

0
悬赏园豆:100 [已解决问题] 解决于 2019-11-26 09:58

如下所示,线程已经没有任务了,一直出现该异常;求解。

spring.thread.pool.corePoolSize=10
spring.thread.pool.maxPoolSize=100
spring.thread.pool.keepAliveSeconds=300
spring.thread.pool.queueCapacity=200
spring.thread.pool.threadNamePrefix=AbilityExecutor

问题定位到这一行: 其中,mod = 4
for(int i=0;i<mod;i++) {
calls.add(new TicketArchiveCallable(idleSleep,
pooltimeout,topic+String.valueOf(i),props,ticketTransferService,cacheCapCodeService,rzLines,serilNumbePath));
}
CompletionService<Boolean> completionService=null;
try {
completionService = new ExecutorCompletionService<Boolean>(
executorService);
List<Future<Boolean>> futures=new ArrayList();
for (int i = 0; i < calls.size(); i++) {
//异常提示在这一行
futures.add(completionService.submit(calls.get(i)));
}

java.util.concurrent.RejectedExecutionException: Task java.util.concurrent.ExecutorCompletionService$QueueingFuture@47a627cc rejected from java.util.concurrent.ThreadPoolExecutor@5acbef42[Terminated, pool size = 0, active threads = 0, queued tasks = 0, completed tasks = 4]
at java.util.concurrent.ThreadPoolExecutor$AbortPolicy.rejectedExecution(ThreadPoolExecutor.java:2063) ~[?:1.8.0_144]
at java.util.concurrent.ThreadPoolExecutor.reject(ThreadPoolExecutor.java:830) ~[?:1.8.0_144]
at java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:1379) ~[?:1.8.0_144]
at java.util.concurrent.ExecutorCompletionService.submit(ExecutorCompletionService.java:181) ~[?:1.8.0_144]
at com.aspire.ability.file.job.NewTicketArchiveJob.run(NewTicketArchiveJob.java:150) [Ability-Work-1.0.1-OnLine-File.jar:1.0.1-OnLine]
at sun.reflect.GeneratedMethodAccessor261.invoke(Unknown Source) ~[?:?]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_144]
at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_144]
at org.springframework.scheduling.support.ScheduledMethodRunnable.run(ScheduledMethodRunnable.java:65) [spring-context-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54) [spring-context-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:1.8.0_144]
at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308) [?:1.8.0_144]

明日小路的主页 明日小路 | 菜鸟二级 | 园豆:466
提问于:2019-11-15 10:46
< >
分享
最佳答案
0

AbortPolicy是线程池默认的拒绝策略,当你的线程跑满,并且等待队列也满了以后,再执行任务,就会报错,抛弃掉新增的任务
你的线程池最大是100,队列是200,所以你任务跑多了,就会报错

收获园豆:100
yytxdy | 小虾三级 |园豆:1680 | 2019-11-15 11:31

谢谢解答,但是 mod=4 ,每分钟启动一次,每次启动4条线程; 而且线程都没有任务执行(因为处理线程没有满足需要处理任务的条件)
List<Callable<Boolean>> calls=new ArrayList();

    for(int i=0;i<mod;i++) {
        calls.add(new TicketArchiveCallable(idleSleep,
                pooltimeout,topic+String.valueOf(i),props,ticketTransferService,cacheCapCodeService,rzLines,serilNumbePath));
    }
明日小路 | 园豆:466 (菜鸟二级) | 2019-11-15 11:35

@南小鸟: 肯定还是拒绝问题,你可以DEBUG跟到AbortPolicy里看一下,你的线程池是什么情况,或者用Jconsole看一下,另外使用线程池的话,最好重写ThreadFactory,给线程一个明确的名字,这样排查问题会方便一点

yytxdy | 园豆:1680 (小虾三级) | 2019-11-15 11:51

@杨宇的爸爸: 好的谢谢。

明日小路 | 园豆:466 (菜鸟二级) | 2019-11-15 14:27
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册