Announcement Announcement Module
Collapse
No announcement yet.
Setting rejectedExecutionHandler on ThreadPoolTaskExecutor Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • 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"/>
    </property>
    </bean>

    The resulting error is:

    Caused by: java.lang.ClassNotFoundException: java.util.concurrent.ThreadPoolExecutor.CallerRuns Policy
    at org.apache.catalina.loader.WebappClassLoader.loadC lass(WebappClassLoader.java:1358)
    at org.apache.catalina.loader.WebappClassLoader.loadC lass(WebappClassLoader.java:1204)
    at org.springframework.util.ClassUtils.forName(ClassU tils.java:230)
    at org.springframework.beans.factory.support.Abstract BeanDefinition.resolveBeanClass(AbstractBeanDefini tion.java
    :371)

    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" />

    Comment

    Working...
    X