Java Code Examples for org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler#setAwaitTerminationSeconds()

The following examples show how to use org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler#setAwaitTerminationSeconds() . 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: TaskPoolConfig.java    From paas with Apache License 2.0 6 votes vote down vote up
@Bean("taskExecutor")
public Executor taskExecutor() {
    ThreadPoolTaskScheduler executor = new ThreadPoolTaskScheduler();
    //最大线程数30
    executor.setPoolSize(30);
    //线程池名的前缀
    executor.setThreadNamePrefix("taskExecutor-");
    //设置线程池关闭的时候等待所有任务都完成再继续销毁其他的Bean
    executor.setWaitForTasksToCompleteOnShutdown(true);
    //设置线程池中任务的等待时间
    executor.setAwaitTerminationSeconds(60);
    //当线程池没有处理能力的时候,该策略会直接在 execute 方法的调用线程中运行被拒绝的任务;如果执行程序已关闭,则会丢弃该任务
    executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());

    return executor;
}
 
Example 2
Source File: ThreadPoolConfig.java    From WeBASE-Node-Manager with Apache License 2.0 5 votes vote down vote up
/**
 * thread pool for scheduler parallel task (not async):
 * pull block, trans monitor, statistic trans, delete info, reset groupList
 * @return ThreadPoolTaskScheduler
 */
@Bean(destroyMethod = "shutdown")
public ThreadPoolTaskScheduler mgrTaskScheduler() {
    log.info("start mgrTaskScheduler init..");
    ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
    scheduler.setPoolSize(schedulerProperties.getPoolSize());
    scheduler.setThreadNamePrefix(schedulerProperties.getThreadNamePrefix());
    scheduler.setAwaitTerminationSeconds(schedulerProperties.getAwaitTerminationSeconds());
    scheduler.setWaitForTasksToCompleteOnShutdown(
            schedulerProperties.getWaitForTasksToCompleteOnShutdown());
    return scheduler;
}
 
Example 3
Source File: ThreadUtils.java    From rqueue with Apache License 2.0 5 votes vote down vote up
public static ThreadPoolTaskScheduler createTaskScheduler(
    int poolSize, String threadPrefix, int terminationTime) {
  ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
  scheduler.setBeanName(threadPrefix.substring(0, threadPrefix.length() - 1));
  scheduler.setPoolSize(poolSize);
  scheduler.setThreadNamePrefix(threadPrefix);
  scheduler.setAwaitTerminationSeconds(terminationTime);
  scheduler.setRemoveOnCancelPolicy(true);
  scheduler.afterPropertiesSet();
  return scheduler;
}
 
Example 4
Source File: SchedulingConfiguration.java    From dk-foundation with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Bean(destroyMethod = "shutdown")
public ThreadPoolTaskScheduler taskScheduler() {
    ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
    scheduler.setPoolSize(systemSchedulePoolsize);
    scheduler.setThreadNamePrefix("dispatch-");
    scheduler.setAwaitTerminationSeconds(600);
    scheduler.setErrorHandler(throwable -> logger.error("调度任务发生异常", throwable));
    scheduler.setWaitForTasksToCompleteOnShutdown(true);
    return scheduler;
}
 
Example 5
Source File: ScheduledThreadPoolConfig.java    From hdw-dubbo with Apache License 2.0 5 votes vote down vote up
@Bean(destroyMethod = "shutdown")
public ThreadPoolTaskScheduler taskScheduler() {
    ThreadPoolTaskScheduler executor = new ThreadPoolTaskScheduler();
    // 设置默认线程名称
    executor.setThreadNamePrefix(env.getProperty("spring.application.name") + "-task-");
    // 设置最大线程数
    executor.setPoolSize(new Double(Math.floor(Runtime.getRuntime().availableProcessors() / (1 - 0.9))).intValue());
    // 设置线程活跃时间(秒)
    executor.setAwaitTerminationSeconds(60);
    // 设置拒绝策略
    executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
    // 等待所有任务结束后再关闭线程池
    executor.setWaitForTasksToCompleteOnShutdown(true);
    return executor;
}
 
Example 6
Source File: ScheduleConfig.java    From Alice-LiveMan with GNU Affero General Public License v3.0 5 votes vote down vote up
@Bean(destroyMethod = "shutdown")
public ThreadPoolTaskScheduler taskScheduler() {
    ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
    scheduler.setPoolSize(10);
    scheduler.setThreadNamePrefix("task-"); //设置线程名开头
    scheduler.setAwaitTerminationSeconds(120);
    scheduler.setWaitForTasksToCompleteOnShutdown(true);
    return scheduler;
}
 
Example 7
Source File: CommonConfiguration.java    From JuniperBot with GNU General Public License v3.0 5 votes vote down vote up
@Bean(SCHEDULER)
public TaskScheduler taskScheduler() {
    ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
    scheduler.setPoolSize(commonProperties.getExecution().getSchedulerPoolSize());
    scheduler.setWaitForTasksToCompleteOnShutdown(true);
    scheduler.setAwaitTerminationSeconds(30);
    scheduler.setThreadNamePrefix(SCHEDULER);
    return scheduler;
}
 
Example 8
Source File: GpfdistSinkConfiguration.java    From spring-cloud-stream-app-starters with Apache License 2.0 5 votes vote down vote up
@Bean
public TaskScheduler sqlTaskScheduler() {
	ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler();
	taskScheduler.setWaitForTasksToCompleteOnShutdown(true);
	taskScheduler.setAwaitTerminationSeconds(properties.getBatchTimeout());
	return taskScheduler;
}