My application reads messages through the Jms MessageListener class, and at some point in time it throws a TaskRejectedException . I know that most of you will say that the number of threads exceeded maxPoolSize, and the queue is also full.
But I noticed something. The number of messages sent to the queue from which the MessageListener class is called is 10353, and the spring property for threadPoolExecutor is below:
<bean id="ticketReaderThreadPool" class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor" scope="singleton" destroy-method="destroy">
<property name="corePoolSize" value="10" />
<property name="maxPoolSize" value="150" />
<property name="queueCapacity" value="11000" />
</bean>
Now, in my opinion, maxPoolSize is more than enough to handle these many requests. Therefore, if any of you can explain the reason, besides the violation of maxPoolSize, please do so.
This is the second time we encounter this problem; previously we tried to increase maxPoolSize, but again after 15 days we experience this exception from about 5,000 to 8,000 times a day.
Update:
This is the full trace of the exception stack:
A general exception occurred while reading from the queue / message processing org.springframework.core.task.TaskRejectedException: Executor [ java.util.concurrent.ThreadPoolExecutor@408b9775 ] did not accept the task: com.batman.rapid.rapidserver.sla.TicketHandler@1be5e59898 org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor.execute(ThreadPoolTaskExecutor.java:244) com.batman.rapid.rapidserver.sla.JmsTicketReceiver.onMessage(JmsTicketReceiver.java:58) at org.springframework.jms.listener.AbstractMessageListenerContainer.doInvokeListener(AbstractMessageListenerContainer.java:560) at org.springframework.jms.listener.AbstractMessageListenerContainer.invokeListener(AbstractMessageListenerContainer.java:498) at org.springframework.jms.listener.AbstractMessageListenerContainer.doExecuteListener(AbstractMessageListenerContainer.java:467) org.springframework.jms.listener.AbstractPollingMessageListenerContainer.doReceiveAndExecute(AbstractPollingMessageListenerContainer.java:325) at org.springframework.jms.listener.AbstractPollingMessageListenerContainer.receiveAndExecute(AbstractPollingMessageListenerContainer.java:263) at org.springframework.jms.listener.DefaultMessageListenerContainer $AsyncMessageListenerInvoker.invokeListener(DefaultMessageListenerContainer.java:1058) at org.springframework.jms.listener.DefaultMessageListenerContainer $AsyncMessageListenerInvoker.executeOngoingLoop(DefaultMessageListenerContainer.java:1050) at org.springframework.jms.listener.DefaultMessageListenerContainer $AsyncMessageListenerInvoker.run(DefaultMessageListenerContainer.java:947) java.lang.Thread.run(Thread.java:662) : java.util.concurrent.RejectedExecutionException java.util.concurrent.ThreadPoolExecutor $AbortPolicy.rejectedExecution(ThreadPoolExecutor.java:1774) java.util.concurrent.ThreadPoolExecutor.reject(ThreadPoolExecutor.java:768) java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:656) org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor.execute(ThreadPoolTaskExecutor.java:241) ... 10
:
if (message instanceof TextMessage)
{
textMessage = (TextMessage) message;
ticketReaderThreadPool.execute(new TicketHandler(textMessage.getText()));
}
:
<bean id="ticketReaderThreadPool" class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor" scope="singleton" destroy-method="destroy">
<property name="corePoolSize" value="10" />
<property name="maxPoolSize" value="150" />
<property name="queueCapacity" value="11000" />
</bean>
<bean id="notificationThreadPool" class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor" scope="singleton" destroy-method="destroy">
<property name="corePoolSize" value="10" />
<property name="maxPoolSize" value="100" />
<property name="queueCapacity" value="10000" />
</bean>
<bean id="notificationManager" class="com.batman.rapid.rapidserver.sla.scheduler.NotificationManager" scope="singleton">
<property name="defaultPercent" value="80"></property>
</bean>
<bean id="dbUpdateThreads" class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor" scope="singleton" destroy-method="destroy">
<property name="corePoolSize" value="1" />
<property name="maxPoolSize" value="100" />
<property name="queueCapacity" value="10000" />
</bean>