|
|
@@ -0,0 +1,40 @@ |
|
|
|
package com.telpo.dipperposition.controller; |
|
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.Value; |
|
|
|
import org.springframework.context.annotation.Bean; |
|
|
|
import org.springframework.context.annotation.Configuration; |
|
|
|
import org.springframework.scheduling.annotation.SchedulingConfigurer; |
|
|
|
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; |
|
|
|
import org.springframework.scheduling.config.ScheduledTaskRegistrar; |
|
|
|
|
|
|
|
/** |
|
|
|
* @program: DataPushServer |
|
|
|
* @description: 定时任务线程配置 |
|
|
|
* @author: linwl |
|
|
|
* @create: 2020-07-24 10:53 |
|
|
|
*/ |
|
|
|
@Configuration |
|
|
|
public class SchedulingExecutorConfig implements SchedulingConfigurer { |
|
|
|
|
|
|
|
@Value("${scheduler.pool.size}") |
|
|
|
private int pollSize; |
|
|
|
|
|
|
|
@Value("${scheduler.pool.await-seconds}") |
|
|
|
private int awaitSeconds; |
|
|
|
|
|
|
|
@Override |
|
|
|
public void configureTasks(ScheduledTaskRegistrar taskRegistrar) { |
|
|
|
ThreadPoolTaskScheduler taskScheduler = taskScheduler(); |
|
|
|
taskRegistrar.setTaskScheduler(taskScheduler); |
|
|
|
} |
|
|
|
|
|
|
|
@Bean(destroyMethod = "shutdown", name = "taskScheduler") |
|
|
|
public ThreadPoolTaskScheduler taskScheduler() { |
|
|
|
ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler(); |
|
|
|
scheduler.setPoolSize(pollSize); |
|
|
|
scheduler.setThreadNamePrefix("task-"); |
|
|
|
scheduler.setAwaitTerminationSeconds(awaitSeconds); |
|
|
|
scheduler.setWaitForTasksToCompleteOnShutdown(true); |
|
|
|
return scheduler; |
|
|
|
} |
|
|
|
} |