Java Code Examples for org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor#initialize()

The following examples show how to use org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor#initialize() . 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: TaskExecutorConfig.java    From spring-boot-cookbook with Apache License 2.0 6 votes vote down vote up
@Override
public Executor getAsyncExecutor() {
    ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
    taskExecutor.setCorePoolSize(2);
    taskExecutor.setQueueCapacity(25);//如果任务数大于corePoolSize则放到Queue中,queue只能存放25个阻塞的任务
    //如果需要执行的任务数大于corePoolSize+QueueCapacity则会创建(maxPoolSize-corePoolSize)个线程来继续执行任务
    taskExecutor.setMaxPoolSize(20);
    //如果大于需要执行的任务数大于maxPoolSize+QueueCapacity,
    // 则会根据RejectedExecutionHandler策略来决定怎么处理这些超出上面配置的任务
    //此处使用CallerRunsPolicy:会通过new 一个Thread的方式来执行这些任务
    taskExecutor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
    taskExecutor.setKeepAliveSeconds(60);//实际工作的线程数大于corePoolSize时,如果60s没有被使用则销毁

    taskExecutor.setWaitForTasksToCompleteOnShutdown(true);//线程池会等任务完成后才会关闭
    taskExecutor.setAwaitTerminationSeconds(60);//如果60s后线程仍未关闭,则关闭线程池
    taskExecutor.setThreadNamePrefix("ThreadPoolTaskExecutor-");//实际显示为: [lTaskExecutor-1] c.t.learning.thread.AsyncTaskService     :
    taskExecutor.initialize();
    return taskExecutor;
}
 
Example 2
Source File: AsyncPoolConfig.java    From SpringAll with MIT License 6 votes vote down vote up
@Bean
public ThreadPoolTaskExecutor asyncThreadPoolTaskExecutor(){
    ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
    executor.setCorePoolSize(20);
    executor.setMaxPoolSize(200);
    executor.setQueueCapacity(25);
    executor.setKeepAliveSeconds(200);
    executor.setThreadNamePrefix("asyncThread");
    executor.setWaitForTasksToCompleteOnShutdown(true);
    executor.setAwaitTerminationSeconds(60);

    executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());

    executor.initialize();
    return executor;
}
 
Example 3
Source File: RuleTagPostLoaderProcessor.java    From c2mon with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void initializeThreadPool() {
  executor = new ThreadPoolTaskExecutor();
  executor.setCorePoolSize(threadPoolMin);
  executor.setMaxPoolSize(threadPoolMax);
  executor.setKeepAliveSeconds(THREAD_IDLE_LIMIT);
  executor.setThreadNamePrefix(THREAD_NAME_PREFIX);
  executor.initialize();
}
 
Example 4
Source File: FebsJobConfigure.java    From FEBS-Cloud with Apache License 2.0 5 votes vote down vote up
@Bean
public ThreadPoolTaskExecutor scheduleJobExecutorService() {
    ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
    executor.setCorePoolSize(5);
    executor.setMaxPoolSize(10);
    executor.setQueueCapacity(20);
    executor.setKeepAliveSeconds(30);
    executor.setThreadNamePrefix("Febs-Job-Thread");
    executor.setWaitForTasksToCompleteOnShutdown(true);
    executor.setAwaitTerminationSeconds(60);
    executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
    executor.initialize();
    return executor;
}
 
Example 5
Source File: BatchConfiguration.java    From spring-cloud-release-tools with Apache License 2.0 5 votes vote down vote up
@Bean
TaskExecutor batchTaskExecutor() {
	ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
	executor.setCorePoolSize(4);
	executor.initialize();
	return executor;
}
 
Example 6
Source File: AsycTaskExecutorConfig.java    From open-capacity-platform with Apache License 2.0 5 votes vote down vote up
@Bean
public TaskExecutor taskExecutor() {
	ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
       executor.setCorePoolSize(corePoolSize);
       executor.setMaxPoolSize(maxPoolSize);
       executor.setQueueCapacity(queueCapacity);
       executor.setThreadNamePrefix("MyExecutor-");

       // rejection-policy:当pool已经达到max size的时候,如何处理新任务
       // CALLER_RUNS:不在新线程中执行任务,而是有调用者所在的线程来执行
       executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
       executor.initialize();
       return executor;
}
 
Example 7
Source File: ThreadConfig.java    From WeBASE-Transaction with Apache License 2.0 5 votes vote down vote up
/**
 * set ThreadPoolTaskExecutor.
 * 
 * @return
 */
@Bean
public ThreadPoolTaskExecutor transExecutor() {
    ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
    executor.setCorePoolSize(50);
    executor.setMaxPoolSize(100);
    executor.setQueueCapacity(500);
    executor.setKeepAliveSeconds(60);
    executor.setRejectedExecutionHandler(new AbortPolicy());
    executor.setThreadNamePrefix("transExecutor-");
    executor.initialize();
    return executor;
}
 
Example 8
Source File: WebConfigration.java    From FATE-Serving with Apache License 2.0 5 votes vote down vote up
@Override
public void configureAsyncSupport(AsyncSupportConfigurer configurer) {
    ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
    executor.setCorePoolSize(coreSize>0?coreSize:processors);
    executor.setMaxPoolSize(maxSize>0?maxSize:2*processors);
    executor.setThreadNamePrefix("ProxyAsync");
    executor.setRejectedExecutionHandler(new ThreadPoolExecutor.AbortPolicy());
    executor.initialize();
    configurer.setTaskExecutor(executor);
    configurer.setDefaultTimeout(timeout);
    configurer.registerCallableInterceptors(new TimeoutCallableProcessingInterceptor());
}
 
Example 9
Source File: Web3Config.java    From WeBASE-Front with Apache License 2.0 5 votes vote down vote up
/**
 * set sdk threadPool.
 *
 * @return
 */
@Bean
public ThreadPoolTaskExecutor sdkThreadPool() {
    ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
    executor.setCorePoolSize(corePoolSize);
    executor.setMaxPoolSize(maxPoolSize);
    executor.setQueueCapacity(queueCapacity);
    executor.setKeepAliveSeconds(keepAlive);
    executor.setRejectedExecutionHandler(new AbortPolicy());
    executor.setThreadNamePrefix("sdkThreadPool-");
    executor.initialize();
    return executor;
}
 
Example 10
Source File: ParallelXsltTest.java    From iaf with Apache License 2.0 5 votes vote down vote up
protected SenderSeries createSenderContainer() {
	SenderSeries senders=new ParallelSenders() {
		@Override
		protected TaskExecutor createTaskExecutor() {
			ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
			taskExecutor.setCorePoolSize(NUM_SENDERS);
			taskExecutor.initialize();
			return taskExecutor;
		}
	};
	return senders;		
}
 
Example 11
Source File: FetchingCacheServiceImplTest.java    From genie with Apache License 2.0 5 votes vote down vote up
/**
 * Set up.
 *
 * @throws Exception the exception
 */
@Before
public void setUp() throws Exception {
    uri = new URI("https://my-server.com/path/to/config/config.xml");
    cacheArguments = Mockito.mock(ArgumentDelegates.CacheArguments.class);
    Mockito.when(
        cacheArguments.getCacheDirectory()
    ).thenReturn(temporaryFolder.getRoot());
    targetFile = new File(temporaryFolder.getRoot(), "target");
    cleanUpTaskExecutor = new ThreadPoolTaskExecutor();
    cleanUpTaskExecutor.setCorePoolSize(1);
    cleanUpTaskExecutor.initialize();
}
 
Example 12
Source File: AsyncProcessLoggerConfiguration.java    From multiapps-controller with Apache License 2.0 5 votes vote down vote up
@Bean("asyncExecutor")
public Executor getAsyncExecutor() {
    ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
    executor.setCorePoolSize(configuration.getFlowableJobExecutorCoreThreads());
    executor.setMaxPoolSize(configuration.getFlowableJobExecutorMaxThreads());
    executor.setQueueCapacity(configuration.getFlowableJobExecutorQueueCapacity());
    executor.initialize();
    return executor;
}
 
Example 13
Source File: AppConfiguration.java    From elasticactors with Apache License 2.0 5 votes vote down vote up
@Override
@Bean(name = "asyncExecutor")
public Executor getAsyncExecutor() {
    ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
    executor.setCorePoolSize(Runtime.getRuntime().availableProcessors());
    executor.setMaxPoolSize(Runtime.getRuntime().availableProcessors() * 3);
    executor.setQueueCapacity(1024);
    executor.setThreadNamePrefix("ASYNCHRONOUS-ANNOTATION-EXECUTOR-");
    executor.initialize();
    return executor;
}
 
Example 14
Source File: AppConfig.java    From staffjoy with MIT License 5 votes vote down vote up
@Bean(name=ASYNC_EXECUTOR_NAME)
public Executor asyncExecutor() {
    ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
    executor.setCorePoolSize(appProps.getConcurrency());
    executor.setMaxPoolSize(appProps.getConcurrency());
    executor.setQueueCapacity(SmsConstant.DEFAULT_EXECUTOR_QUEUE_CAPACITY);
    executor.setWaitForTasksToCompleteOnShutdown(true);
    executor.setThreadNamePrefix("AsyncThread-");
    executor.initialize();
    return executor;
}
 
Example 15
Source File: BrokerApplication.java    From WeEvent with Apache License 2.0 5 votes vote down vote up
@Bean
public Executor taskExecutor() {
    ThreadPoolTaskExecutor pool = new ThreadPoolTaskExecutor();
    pool.setThreadNamePrefix("weevent-executor-");
    // run in thread immediately, no blocking queue
    pool.setQueueCapacity(0);
    pool.setDaemon(true);
    pool.initialize();

    log.info("init daemon thread pool");
    return pool;
}
 
Example 16
Source File: AsyncScheduledConfig.java    From springboot-learn with MIT License 5 votes vote down vote up
@Bean
public ThreadPoolTaskExecutor taskExecutor() {
    ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
    executor.setCorePoolSize(corePoolSize);
    executor.setMaxPoolSize(maxPoolSize);
    executor.setQueueCapacity(queueCapacity);

    executor.initialize();

    return executor;
}
 
Example 17
Source File: FlowRunnerTaskExecutorSupplier.java    From spring-cloud-release-tools with Apache License 2.0 5 votes vote down vote up
@Override
default TaskExecutor get() {
	ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
	executor.setCorePoolSize(4);
	executor.initialize();
	return executor;
}
 
Example 18
Source File: TaskExecution.java    From data-prep with Apache License 2.0 5 votes vote down vote up
/**
 * @return an Authenticated task executor for event multi casting.
 * @see DataPrepEvents
 */
@Bean(name = "applicationEventMulticaster#executor")
public TaskExecutor dataPrepAsyncTaskExecutor() {
    final ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
    taskExecutor.setCorePoolSize(2);
    taskExecutor.setMaxPoolSize(10);
    taskExecutor.setWaitForTasksToCompleteOnShutdown(false);
    taskExecutor.initialize();
    return taskExecutor;
}
 
Example 19
Source File: Application.java    From sitemonitoring-production with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public Executor getAsyncExecutor() {
    ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
    executor.setMaxPoolSize(10);
    executor.setCorePoolSize(5);
    executor.initialize();
    return executor;
}
 
Example 20
Source File: BusinessConfig.java    From konker-platform with Apache License 2.0 4 votes vote down vote up
@Override
public Executor getAsyncExecutor() {
    ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
    executor.initialize();
    return executor;
}