Announcement Announcement Module
No announcement yet.
Setting rejectedExecutionHandler on ThreadPoolTaskExecutor Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Setting rejectedExecutionHandler on ThreadPoolTaskExecutor

    I'm trying to set the rejectExecutionHandler on the ThreadPoolTaskExecutor bean with:

    <bean id="executor"
    class="org.springframework.scheduling.concurrent.T hreadPoolTaskExecutor">
    <property name="rejectedExecutionHandler">
    <bean class="java.util.concurrent.ThreadPoolExecutor.Cal lerRunsPolicy"/>

    The resulting error is:

    Caused by: java.lang.ClassNotFoundException: java.util.concurrent.ThreadPoolExecutor.CallerRuns Policy
    at org.apache.catalina.loader.WebappClassLoader.loadC lass(
    at org.apache.catalina.loader.WebappClassLoader.loadC lass(
    at org.springframework.util.ClassUtils.forName(ClassU
    at BeanDefinition.resolveBeanClass(AbstractBeanDefini

    There appears to be an issue with using a public static inner class as the class for the bean.

    To get around this we specified a wrapper class:

    import java.util.concurrent.ThreadPoolExecutor;

    import org.springframework.beans.factory.FactoryBean;

    public class CallerRunsPolicyFactoryBean
    implements FactoryBean

    public Object getObject() throws Exception
    return new ThreadPoolExecutor.CallerRunsPolicy();

    public Class getObjectType()
    return ThreadPoolExecutor.CallerRunsPolicy.class;

    public boolean isSingleton()
    return true;


    and used it for the bean definition.

    Is this the expected behavior?

  • #2
    You need to tell Spring it's a static inner class, for instance:

    <bean id="generalCallerRunsPolicy" class="java.util.concurrent.ThreadPoolExecutor$Cal lerRunsPolicy" />