List of usage examples for org.springframework.scheduling.concurrent ThreadPoolTaskExecutor setRejectedExecutionHandler
public void setRejectedExecutionHandler(@Nullable RejectedExecutionHandler rejectedExecutionHandler)
From source file:com.aol.advertising.qiao.util.CommonUtils.java
public static ThreadPoolTaskExecutor createFixedThreadPoolExecutor(int threadPoolSize) { ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); executor.setCorePoolSize(threadPoolSize); executor.setMaxPoolSize(threadPoolSize); executor.setQueueCapacity(0);/*from w w w. ja v a 2 s . co m*/ executor.setRejectedExecutionHandler(new CallerRunsPolicy()); return executor; }
From source file:com.aol.advertising.qiao.util.CommonUtils.java
public static ThreadPoolTaskExecutor createThreadPoolExecutor(int corePoolSize, int maxPoolSize, int queueCapacity) { ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); executor.setCorePoolSize(corePoolSize); executor.setMaxPoolSize(maxPoolSize); executor.setQueueCapacity(queueCapacity); executor.setRejectedExecutionHandler(new CallerRunsPolicy()); return executor; }
From source file:com.epam.ta.reportportal.core.configs.JobsConfiguration.java
@Bean(name = "saveLogsTaskExecutor") public TaskExecutor saveLogsTaskExecutor() { ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); executor.setCorePoolSize(20);// w ww.j a v a 2 s . c o m executor.setMaxPoolSize(200); executor.setQueueCapacity(400); executor.setAllowCoreThreadTimeOut(true); executor.setThreadNamePrefix("logs-task-exec"); executor.setRejectedExecutionHandler(new java.util.concurrent.ThreadPoolExecutor.CallerRunsPolicy()); return executor; }
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 www .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.repeat.support.TaskExecutorRepeatTemplateBulkAsynchronousTests.java
@Test public void testThrottleLimitEarlyFinishThreadStarvation() throws Exception { early = 2;//from ww w.ja va 2 s.c o m ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor(); // Set the concurrency limit below the throttle limit for possible // starvation condition taskExecutor.setMaxPoolSize(20); taskExecutor.setCorePoolSize(10); taskExecutor.setQueueCapacity(0); // This is the most sensible setting, otherwise the bookkeeping in // ResultHolderResultQueue gets out of whack when tasks are aborted. taskExecutor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy()); taskExecutor.afterPropertiesSet(); template.setTaskExecutor(taskExecutor); template.iterate(callback); int frequency = Collections.frequency(items, "null"); // System.err.println("Frequency: " + frequency); // System.err.println("Items: " + items); // Extra tasks will be submitted before the termination is detected assertEquals(total, items.size() - frequency); assertTrue(frequency <= throttleLimit + 1); taskExecutor.destroy(); }
From source file:org.springframework.integration.ip.tcp.connection.TcpNioConnectionTests.java
private CompositeExecutor compositeExecutor() { ThreadPoolTaskExecutor ioExec = new ThreadPoolTaskExecutor(); ioExec.setCorePoolSize(2);/* w w w .j a va 2 s . com*/ ioExec.setMaxPoolSize(4); ioExec.setQueueCapacity(0); ioExec.setThreadNamePrefix("io-"); ioExec.setRejectedExecutionHandler(new AbortPolicy()); ioExec.initialize(); ThreadPoolTaskExecutor assemblerExec = new ThreadPoolTaskExecutor(); assemblerExec.setCorePoolSize(2); assemblerExec.setMaxPoolSize(5); assemblerExec.setQueueCapacity(0); assemblerExec.setThreadNamePrefix("assembler-"); assemblerExec.setRejectedExecutionHandler(new AbortPolicy()); assemblerExec.initialize(); return new CompositeExecutor(ioExec, assemblerExec); }