Java tutorial
/* ---------------------------------------------------------------------------- * All rights reserved 2017 salvadorgnolasco. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * --------------------------------------------------------------------------- * File name: ServiceConfig.java * Original Author: Salvador Gonzalez Nolasco. * Creation Date: 12/02/2017 * --------------------------------------------------------------------------- */ package org.tocode.poc.service.config; import java.util.concurrent.Executor; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.scheduling.annotation.AsyncConfigurerSupport; import org.springframework.scheduling.annotation.EnableAsync; import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; import org.tocode.poc.aggregator.TransactionAAggregator; import org.tocode.poc.aggregator.TransactionBAggregator; import org.tocode.poc.formatter.TransactionAFormatter; import org.tocode.poc.formatter.TransactionBFormatter; import org.tocode.poc.service.PocService; /** * The Class ServiceConfig. */ @Configuration @EnableAsync public class ServiceConfig extends AsyncConfigurerSupport { /** * Service A. * * @return the poc service */ @Bean public PocService serviceA() { PocService service = new PocService(); service.setAggregator(new TransactionAAggregator()); service.setFormatter(new TransactionAFormatter()); return service; } /** * Service B. * * @return the poc service */ @Bean public PocService serviceB() { PocService service = new PocService(); service.setAggregator(new TransactionBAggregator()); service.setFormatter(new TransactionBFormatter()); return service; } /* * (non-Javadoc) * * @see org.springframework.scheduling.annotation.AsyncConfigurerSupport# * getAsyncExecutor() */ @Override public Executor getAsyncExecutor() { ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); executor.setCorePoolSize(20); executor.setMaxPoolSize(50); executor.setQueueCapacity(500); executor.setThreadNamePrefix("Service-Thread"); executor.initialize(); return executor; } }