org.springframework.scheduling.concurrent.ThreadPoolExecutorFactoryBean Java Examples

The following examples show how to use org.springframework.scheduling.concurrent.ThreadPoolExecutorFactoryBean. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ExecutorConfiguration.java    From jetlinks-community with Apache License 2.0 6 votes vote down vote up
@Bean
@ConfigurationProperties(prefix = "jetlinks.executor")
@Primary
public FactoryBean<ScheduledExecutorService> threadPoolTaskExecutor() {
    ThreadPoolExecutorFactoryBean executor = new ThreadPoolExecutorFactoryBean() {
        @Override
        protected ScheduledThreadPoolExecutor createExecutor(int corePoolSize, int maxPoolSize, int keepAliveSeconds, BlockingQueue<Runnable> queue, ThreadFactory threadFactory, RejectedExecutionHandler rejectedExecutionHandler) {

            ScheduledThreadPoolExecutor poolExecutor = new ScheduledThreadPoolExecutor(corePoolSize, threadFactory);
            poolExecutor.setMaximumPoolSize(maxPoolSize);
            poolExecutor.setRejectedExecutionHandler(rejectedExecutionHandler);
            poolExecutor.setKeepAliveTime(keepAliveSeconds, TimeUnit.SECONDS);

            return poolExecutor;
        }
    };
    executor.setThreadNamePrefix("jetlinks-thread-");
    executor.setCorePoolSize(Runtime.getRuntime().availableProcessors() * 2);

    return (FactoryBean) executor;
}
 
Example #2
Source File: ExecutorConfiguration.java    From spring-data-dev-tools with Apache License 2.0 5 votes vote down vote up
@Bean
public ThreadPoolExecutorFactoryBean executorService() {

	int processors = Runtime.getRuntime().availableProcessors();
	int threadCount = Math.max(2, processors - 4);
	log.info(String.format("Setting up Executor Service with %d Threads", threadCount));

	ThreadPoolExecutorFactoryBean scheduler = new ThreadPoolExecutorFactoryBean();
	scheduler.setCorePoolSize(threadCount);
	scheduler.setQueueCapacity(32);

	return scheduler;
}
 
Example #3
Source File: Application.java    From chaos-lemur with Apache License 2.0 5 votes vote down vote up
@Bean(destroyMethod = "shutdown")
ThreadPoolExecutorFactoryBean executor() {
    ThreadPoolExecutorFactoryBean factoryBean = new ThreadPoolExecutorFactoryBean();
    factoryBean.setQueueCapacity(5);
    factoryBean.setCorePoolSize(5);
    factoryBean.setMaxPoolSize(20);
    factoryBean.setThreadNamePrefix("destroyer-");

    return factoryBean;
}
 
Example #4
Source File: AppConfig.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
@Bean
public ThreadPoolExecutorFactoryBean getThreadPoolExecutorFactoryBean() {
    ThreadPoolExecutorFactoryBean executorFactoryBean = new ThreadPoolExecutorFactoryBean();
    executorFactoryBean.setCorePoolSize(corePoolSize);
    executorFactoryBean.setMaxPoolSize(maxPoolSize);
    executorFactoryBean.setQueueCapacity(queueCapacity);
    executorFactoryBean.setRejectedExecutionHandler(persistRejectedThreadExecutionHandler);
    return executorFactoryBean;
}
 
Example #5
Source File: RejectedThreadContext.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
@Bean
public ThreadPoolExecutorFactoryBean getThreadPoolExecutorFactoryBean() {
    ThreadPoolExecutorFactoryBean executorFactoryBean = new ThreadPoolExecutorFactoryBean();
    executorFactoryBean.setCorePoolSize(1);
    executorFactoryBean.setMaxPoolSize(2);
    executorFactoryBean.setQueueCapacity(2);
    executorFactoryBean.setRejectedExecutionHandler(persistRejectedThreadExecutionHandler);
    return executorFactoryBean;
}
 
Example #6
Source File: StackCollectorContext.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
@Bean
public ThreadPoolExecutorFactoryBean getThreadPoolExecutorFactoryBean() {
    ThreadPoolExecutorFactoryBean executorFactoryBean = new ThreadPoolExecutorFactoryBean();
    executorFactoryBean.setCorePoolSize(1);
    executorFactoryBean.setMaxPoolSize(2);
    executorFactoryBean.setQueueCapacity(2);
    executorFactoryBean.setRejectedExecutionHandler(persistRejectedThreadExecutionHandler);
    return executorFactoryBean;
}
 
Example #7
Source File: ShellConfiguration.java    From ambari-shell with Apache License 2.0 4 votes vote down vote up
@Bean
ThreadPoolExecutorFactoryBean getThreadPoolExecutorFactoryBean() {
  return new ThreadPoolExecutorFactoryBean();
}