0

I'm not familiar with all Spring Framework and I am trying to convert *.xml to Java Config in the code below.

I am not sure how should I create the executers and set rejection-policy="ABORT".

XAML file:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:aop="http://www.springframework.org/schema/aop" 
    xmlns:task="http://www.springframework.org/schema/task"
    xmlns:cache="http://www.springframework.org/schema/cache"
    xmlns:p="http://www.springframework.org/schema/p"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
            http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
            http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
            http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.1.xsd
            http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache.xsd">

    <context:annotation-config />
    <task:annotation-driven executor="processorExecutor" />

    <task:executor 
        id="listenerExecutor" 
        pool-size="3-15" 
        queue-capacity="5000"
        rejection-policy="ABORT" />

    <task:executor 
        id="processorExecutor" 
        pool-size="3-15" 
        queue-capacity="5001"
        rejection-policy="ABORT" />

    <bean id='applicationEventMulticaster'
        class='org.springframework.context.event.SimpleApplicationEventMulticaster'>
        <property name='taskExecutor' ref='listenerExecutor' />
</bean>

<bean id="config"class="com.ebay.catalogs.pm.common.config.ApplicationConfigPropertiesFactorBean" />
</beans>

Java config file:

@Configuration
public class ApplicationConfig {
    @Bean(name = "listenerExecutor")
    public Executor threadPoolTaskExecutor() {
        ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();

        taskExecutor.setCorePoolSize(3);
        taskExecutor.setMaxPoolSize(15);
        taskExecutor.setQueueCapacity(5000);
        taskExecutor.setr

        return taskExecutor;
    }

    @Bean(name = "processorExecutor")
    public Executor threadPoolTaskExecutor() {
        ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();

        taskExecutor.setCorePoolSize(3);
        taskExecutor.setMaxPoolSize(15);
        taskExecutor.setQueueCapacity(5001);
        taskExecutor.setr

        return taskExecutor;
    }
}
1
  • Next time pls watch youre Code Format! Commented Nov 20, 2017 at 15:24

1 Answer 1

1
 taskExecutor.setRejectedExecutionHandler(new ThreadPoolExecutor.AbortPolicy());
Sign up to request clarification or add additional context in comments.

2 Comments

OK, thanks. and how should I define the task:annotation-driven?
You don't need to define that. If you are using spring-boot then it knows which directories to scan for spring beans based on directory structure. If not you can specify which directories to scan using @ComponentScan.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.