Reputation: 3328
I'm using Spring to create web application where several users can upload file and with asynchronous task I convert this file. Now sometime I receive this exception and tomcat goes down:
Caused by: org.springframework.core.task.TaskRejectedException: Executor [java.util.concurrent.ThreadPoolExecutor@54a611af[Running, pool size = 10, active threads = 10, queued tasks = 10, completed tasks = 230]] did not accept task: org.springframework.aop.interceptor.AsyncExecutionInterceptor$1@598b845a
at org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor.submit(ThreadPoolTaskExecutor.java:284)
at org.springframework.aop.interceptor.AsyncExecutionAspectSupport.doSubmit(AsyncExecutionAspectSupport.java:189)
at org.springframework.aop.interceptor.AsyncExecutionInterceptor.invoke(AsyncExecutionInterceptor.java:123)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:655)
at com.model.ZipAndMat$$EnhancerBySpringCGLIB$$5bcfcf5.createZipAndMat(<generated>)
at com.services.FleetAcquisitionServicesImpl.uploadFiles(FleetAcquisitionServicesImpl.java:95)
... 81 more
Caused by: java.util.concurrent.RejectedExecutionException: Task java.util.concurrent.FutureTask@5a47368c rejected from java.util.concurrent.ThreadPoolExecutor@54a611af[Running, pool size = 10, active threads = 10, queued tasks = 10, completed tasks = 230]
at java.util.concurrent.ThreadPoolExecutor$AbortPolicy.rejectedExecution(ThreadPoolExecutor.java:2047)
at java.util.concurrent.ThreadPoolExecutor.reject(ThreadPoolExecutor.java:823)
at java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:1369)
at java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:134)
at org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor.submit(ThreadPoolTaskExecutor.java:281)
... 87 more
How can I manage this problem? I thought to increase queue size and when it is full the other task should wait until queue has a free slot. Thanks
Upvotes: 4
Views: 7257
Reputation: 333
You must not use taskexecutor if your task size exceeds your queue size. Change your method. For example, write your all request into a permanent store (database, or file etc.) and create a job reads from the store and executes in the manner of sequential processing.
Upvotes: 1