List of usage examples for org.springframework.scheduling.concurrent ThreadPoolTaskExecutor setMaxPoolSize
public void setMaxPoolSize(int maxPoolSize)
From source file:com.sinosoft.one.mvc.web.portal.impl.PortalBeanPostProcessor.java
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { if (applicationContext instanceof WebApplicationContext) { WebApplicationContext webApplicationContext = (WebApplicationContext) applicationContext; if (ThreadPoolTaskExecutor.class == bean.getClass()) { ThreadPoolTaskExecutor executor = (ThreadPoolTaskExecutor) bean; String paramCorePoolSize = webApplicationContext.getServletContext() .getInitParameter(PORTAL_EXECUTOR_CORE_POOL_SIZE); if (StringUtils.isNotBlank(paramCorePoolSize)) { if (logger.isInfoEnabled()) { logger.info("found param " + PORTAL_EXECUTOR_CORE_POOL_SIZE + "=" + paramCorePoolSize); }//from w ww . j a v a 2 s. c o m executor.setCorePoolSize(Integer.parseInt(paramCorePoolSize)); } else { throw new IllegalArgumentException( "please add '<context-param><param-name>portalExecutorCorePoolSize</param-name><param-value>a number here</param-value></context-param>' in your web.xml"); } String paramMaxPoolSize = webApplicationContext.getServletContext() .getInitParameter(PORTAL_EXECUTOR_MAX_POOL_SIZE); if (StringUtils.isNotBlank(paramMaxPoolSize)) { if (logger.isInfoEnabled()) { logger.info("found param " + PORTAL_EXECUTOR_MAX_POOL_SIZE + "=" + paramMaxPoolSize); } executor.setMaxPoolSize(Integer.parseInt(paramMaxPoolSize)); } String paramKeepAliveSeconds = webApplicationContext.getServletContext() .getInitParameter(PORTAL_EXECUTOR_KEEP_ALIVE_SECONDS); if (StringUtils.isNotBlank(paramKeepAliveSeconds)) { if (logger.isInfoEnabled()) { logger.info( "found param " + PORTAL_EXECUTOR_KEEP_ALIVE_SECONDS + "=" + paramKeepAliveSeconds); } executor.setKeepAliveSeconds(Integer.parseInt(paramKeepAliveSeconds)); } } else if (List.class.isInstance(bean) && "portalListenerList".equals(beanName)) { String paramListeners = webApplicationContext.getServletContext() .getInitParameter(PORTAL_LISTENERS); @SuppressWarnings("unchecked") List<WindowListener> list = (List<WindowListener>) bean; if (StringUtils.isNotBlank(paramListeners)) { String[] splits = paramListeners.split(",| "); if (logger.isInfoEnabled()) { logger.info("found portalListener config: " + Arrays.toString(splits)); } for (String className : splits) { className = className.trim(); if (className.length() > 0) { try { Class<?> clazz = Class.forName(className); WindowListener l = (WindowListener) BeanUtils.instantiateClass(clazz); list.add(l); if (logger.isInfoEnabled()) { logger.info("add portalListener: " + l); } } catch (Exception e) { logger.error("", e); } } } } } } return bean; }
From source file:com.laxser.blitz.web.portal.impl.PortalBeanPostProcessor.java
@Override public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { if (applicationContext instanceof WebApplicationContext) { WebApplicationContext webApplicationContext = (WebApplicationContext) applicationContext; if (ThreadPoolTaskExecutor.class == bean.getClass()) { ThreadPoolTaskExecutor executor = (ThreadPoolTaskExecutor) bean; String paramCorePoolSize = webApplicationContext.getServletContext() .getInitParameter(PORTAL_EXECUTOR_CORE_POOL_SIZE); if (StringUtils.isNotBlank(paramCorePoolSize)) { if (logger.isInfoEnabled()) { logger.info("found param " + PORTAL_EXECUTOR_CORE_POOL_SIZE + "=" + paramCorePoolSize); }/*ww w . j av a2 s .co m*/ executor.setCorePoolSize(Integer.parseInt(paramCorePoolSize)); } else { throw new IllegalArgumentException( "please add '<context-param><param-name>portalExecutorCorePoolSize</param-name><param-value>a number here</param-value></context-param>' in your web.xml"); } String paramMaxPoolSize = webApplicationContext.getServletContext() .getInitParameter(PORTAL_EXECUTOR_MAX_POOL_SIZE); if (StringUtils.isNotBlank(paramMaxPoolSize)) { if (logger.isInfoEnabled()) { logger.info("found param " + PORTAL_EXECUTOR_MAX_POOL_SIZE + "=" + paramMaxPoolSize); } executor.setMaxPoolSize(Integer.parseInt(paramMaxPoolSize)); } String paramKeepAliveSeconds = webApplicationContext.getServletContext() .getInitParameter(PORTAL_EXECUTOR_KEEP_ALIVE_SECONDS); if (StringUtils.isNotBlank(paramKeepAliveSeconds)) { if (logger.isInfoEnabled()) { logger.info( "found param " + PORTAL_EXECUTOR_KEEP_ALIVE_SECONDS + "=" + paramKeepAliveSeconds); } executor.setKeepAliveSeconds(Integer.parseInt(paramKeepAliveSeconds)); } } else if (List.class.isInstance(bean) && "portalListenerList".equals(beanName)) { String paramListeners = webApplicationContext.getServletContext() .getInitParameter(PORTAL_LISTENERS); @SuppressWarnings("unchecked") List<WindowListener> list = (List<WindowListener>) bean; if (StringUtils.isNotBlank(paramListeners)) { String[] splits = paramListeners.split(",| "); if (logger.isInfoEnabled()) { logger.info("found portalListener config: " + Arrays.toString(splits)); } for (String className : splits) { className = className.trim(); if (className.length() > 0) { try { Class<?> clazz = Class.forName(className); WindowListener l = (WindowListener) BeanUtils.instantiateClass(clazz); list.add(l); if (logger.isInfoEnabled()) { logger.info("add portalListener: " + l); } } catch (Exception e) { logger.error("", e); } } } } } } return bean; }
From source file:org.eclipse.gemini.blueprint.extender.internal.support.ExtenderConfiguration.java
private TaskExecutor createDefaultShutdownTaskExecutor() { ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor(); taskExecutor.setDaemon(true);//from ww w . ja v a 2 s . co m taskExecutor.setCorePoolSize(2); taskExecutor.setMaxPoolSize(3); taskExecutor.setThreadNamePrefix("Gemini Blueprint context shutdown thread"); taskExecutor.afterPropertiesSet(); isShutdownTaskExecutorManagedInternally = true; return taskExecutor; }
From source file:org.finra.dm.service.config.ServiceSpringModuleConfig.java
/** * Returns an Async "task" executor which is also a normal "executor". This is being wired into Activity via the job executor bean. It is also being used by * the "@EnableAsync" annotation and the fact that this class implements AsyncConfigurer. That way, all methods annotated with "@Async" will be executed * asynchronously by this executor. Thus, we have a shared thread pool that handles both Async method calls as well as Activiti asynchronous job executions * (e.g. timers, messages, etc.).//from w w w. j av a2s.c om * * @return the async task executor. */ @Override @Bean // This will call the "initialize" method of the ThreadPoolTaskExecutor automatically. public TaskExecutor getAsyncExecutor() { // Create a Spring thread pool "task" executor that is backed by a JDK Thread Pool Executor. // Use the environment to make the key thread pool parameters configurable although changing them would require a server restart. ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); executor.setCorePoolSize( configurationHelper.getProperty(ConfigurationValue.THREAD_POOL_CORE_POOL_SIZE, Integer.class)); executor.setMaxPoolSize( configurationHelper.getProperty(ConfigurationValue.THREAD_POOL_MAX_POOL_SIZE, Integer.class)); executor.setKeepAliveSeconds( configurationHelper.getProperty(ConfigurationValue.THREAD_POOL_KEEP_ALIVE_SECS, Integer.class)); return executor; }
From source file:org.finra.herd.service.config.ServiceSpringModuleConfig.java
/** * Activiti's dedicated TaskExecutor bean definition. * * @return TaskExecutor//from w w w. j a v a2 s. c om */ @Bean public TaskExecutor activitiTaskExecutor() { ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor(); taskExecutor.setCorePoolSize(configurationHelper .getProperty(ConfigurationValue.ACTIVITI_THREAD_POOL_CORE_POOL_SIZE, Integer.class)); taskExecutor.setMaxPoolSize(configurationHelper .getProperty(ConfigurationValue.ACTIVITI_THREAD_POOL_MAX_POOL_SIZE, Integer.class)); taskExecutor.setKeepAliveSeconds(configurationHelper .getProperty(ConfigurationValue.ACTIVITI_THREAD_POOL_KEEP_ALIVE_SECS, Integer.class)); taskExecutor.setQueueCapacity(configurationHelper .getProperty(ConfigurationValue.ACTIVITI_THREAD_POOL_QUEUE_CAPACITY, Integer.class)); return taskExecutor; }
From source file:org.flockdata.helper.ExecutorHelper.java
public static Executor getExecutor(String name, String poolSize, int qCapacity) { ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); String vals[] = StringUtils.split(poolSize, "-"); executor.setCorePoolSize(Integer.parseInt(vals[0])); if (vals.length == 2) executor.setMaxPoolSize(Integer.parseInt(vals[1])); else/*from w w w . ja v a 2 s. c o m*/ executor.setMaxPoolSize(Integer.parseInt(vals[0])); executor.setQueueCapacity(qCapacity); executor.setThreadNamePrefix(name + "-"); executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy()); executor.initialize(); return executor.getThreadPoolExecutor(); }
From source file:org.springframework.batch.core.test.step.FaultTolerantStepFactoryBeanIntegrationTests.java
@Before public void setUp() throws Exception { writer = new SkipWriterStub(dataSource); processor = new SkipProcessorStub(dataSource); factory = new FaultTolerantStepFactoryBean<String, String>(); factory.setBeanName("stepName"); factory.setTransactionManager(transactionManager); factory.setJobRepository(repository); factory.setCommitInterval(3);//from ww w . ja v a2 s . c o m ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor(); taskExecutor.setCorePoolSize(3); taskExecutor.setMaxPoolSize(6); taskExecutor.setQueueCapacity(0); taskExecutor.afterPropertiesSet(); factory.setTaskExecutor(taskExecutor); JdbcTestUtils.deleteFromTables(new JdbcTemplate(dataSource), "ERROR_LOG"); }
From source file:org.springframework.batch.core.test.step.FaultTolerantStepFactoryBeanRollbackIntegrationTests.java
@Test public void testMultithreadedSkipInWriter() throws Throwable { ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor(); taskExecutor.setCorePoolSize(3);//from www.j a va 2 s.c o m taskExecutor.setMaxPoolSize(6); taskExecutor.setQueueCapacity(0); taskExecutor.afterPropertiesSet(); factory.setTaskExecutor(taskExecutor); @SuppressWarnings("unchecked") Map<Class<? extends Throwable>, Boolean> skippable = getExceptionMap(Exception.class); factory.setSkippableExceptionClasses(skippable); jobExecution = repository.createJobExecution("skipJob", new JobParameters()); for (int i = 0; i < MAX_COUNT; i++) { if (i % 100 == 0) { logger.info("Starting step: " + i); } JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); assertEquals(0, JdbcTestUtils.countRowsInTable(jdbcTemplate, "ERROR_LOG")); try { SkipReaderStub reader = new SkipReaderStub(); reader.clear(); reader.setItems("1", "2", "3", "4", "5"); factory.setItemReader(reader); writer.clear(); factory.setItemWriter(writer); processor.clear(); factory.setItemProcessor(processor); writer.setFailures("1", "2", "3", "4", "5"); Step step = factory.getObject(); stepExecution = jobExecution.createStepExecution(factory.getName()); repository.add(stepExecution); step.execute(stepExecution); assertEquals(BatchStatus.COMPLETED, stepExecution.getStatus()); assertEquals("[]", writer.getCommitted().toString()); assertEquals("[]", processor.getCommitted().toString()); List<String> processed = new ArrayList<String>(processor.getProcessed()); Collections.sort(processed); assertEquals("[1, 1, 2, 2, 3, 3, 4, 4, 5, 5]", processed.toString()); assertEquals(5, stepExecution.getSkipCount()); } catch (Throwable e) { logger.info("Failed on iteration " + i + " of " + MAX_COUNT); throw e; } } }
From source file:org.springframework.batch.core.test.step.MapRepositoryFaultTolerantStepFactoryBeanRollbackTests.java
@SuppressWarnings("unchecked") @Before/*from w w w .j a va2s .c o m*/ public void setUp() throws Exception { reader = new SkipReaderStub(); writer = new SkipWriterStub(); processor = new SkipProcessorStub(); factory = new FaultTolerantStepFactoryBean<String, String>(); factory.setTransactionManager(transactionManager); factory.setBeanName("stepName"); factory.setCommitInterval(3); ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor(); taskExecutor.setCorePoolSize(3); taskExecutor.setMaxPoolSize(6); taskExecutor.setQueueCapacity(0); taskExecutor.afterPropertiesSet(); factory.setTaskExecutor(taskExecutor); factory.setSkipLimit(10); factory.setSkippableExceptionClasses(getExceptionMap(Exception.class)); }
From source file:org.springframework.batch.core.test.step.MapRepositoryFaultTolerantStepFactoryBeanTests.java
@Before public void setUp() throws Exception { reader = new SkipReaderStub(); writer = new SkipWriterStub(); processor = new SkipProcessorStub(); factory = new FaultTolerantStepFactoryBean<String, String>(); factory.setBeanName("stepName"); factory.setTransactionManager(transactionManager); factory.setCommitInterval(3);/*from w w w . j a v a 2s.c om*/ ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor(); taskExecutor.setCorePoolSize(3); taskExecutor.setMaxPoolSize(6); taskExecutor.setQueueCapacity(0); taskExecutor.afterPropertiesSet(); factory.setTaskExecutor(taskExecutor); }