You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
1.6KB

  1. package com.telpo.dipperposition.config;
  2. import lombok.Getter;
  3. import lombok.Setter;
  4. import org.springframework.beans.factory.annotation.Value;
  5. import org.springframework.context.annotation.Bean;
  6. import org.springframework.context.annotation.Configuration;
  7. import org.springframework.scheduling.annotation.SchedulingConfigurer;
  8. import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
  9. import org.springframework.scheduling.config.ScheduledTaskRegistrar;
  10. /**
  11. * @program: DataPushServer
  12. * @description: 定时任务线程配置
  13. * @author: linwl
  14. * @create: 2020-07-24 10:53
  15. */
  16. @Getter
  17. @Setter
  18. @Configuration
  19. public class SchedulingExecutorConfig implements SchedulingConfigurer {
  20. @Value("${scheduler.pool.size}")
  21. private int pollSize;
  22. @Value("${scheduler.pool.await-seconds}")
  23. private int awaitSeconds;
  24. @Value("${pos.ast.server}")
  25. private String astServer;
  26. @Value("${pos.ast.ephAstPort}")
  27. private int ephAstPort;
  28. @Value("${pos.ast.ephAstHexPort}")
  29. private int ephAstHexPort;
  30. @Value("${pos.ast.timeout}")
  31. private int astTimeout;
  32. @Override
  33. public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {
  34. ThreadPoolTaskScheduler taskScheduler = taskScheduler();
  35. taskRegistrar.setTaskScheduler(taskScheduler);
  36. }
  37. @Bean(destroyMethod = "shutdown", name = "taskScheduler")
  38. public ThreadPoolTaskScheduler taskScheduler() {
  39. ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
  40. scheduler.setPoolSize(pollSize);
  41. scheduler.setThreadNamePrefix("task-");
  42. scheduler.setAwaitTerminationSeconds(awaitSeconds);
  43. scheduler.setWaitForTasksToCompleteOnShutdown(true);
  44. return scheduler;
  45. }
  46. }