2

I have a ThreadPoolTaskExecutor for sending emails. Currently it's corePoolSize is 5, and queueCapacity is default i.e. max value of integer (unbounded queue)

<bean id="emailTaskExecutor" class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">
        <property name="corePoolSize" value="5" />
</bean>

The problem I am facing is few of my threads are getting executed and few are not. I have put logs to confirm the same, and comes to a conclusion that the threads are submitted to executor, but they are not even started.

Neither I am getting RejectedExecutionException exception.

What can be the reason of this?

munish
  • 453
  • 6
  • 22

1 Answers1

1

The Threads you submitted to the executor are considered as Runnable,only run()will be executed.Executor does not known it is a Thread,the Executor using internal threads to execute the tasks.So the Thread will not be start(),and the state also will not be changed.

Generally,when using ThreadPoolExecutor,you should wrap your task to a Runnable,not a Thread.

BlackJoker
  • 3,099
  • 2
  • 20
  • 27