SchedulingConfig.java 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package com.its.rota.server.config;
  2. import lombok.Data;
  3. import lombok.extern.slf4j.Slf4j;
  4. import org.springframework.boot.context.properties.ConfigurationProperties;
  5. import org.springframework.context.annotation.Configuration;
  6. import org.springframework.scheduling.annotation.SchedulingConfigurer;
  7. import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
  8. import org.springframework.scheduling.config.ScheduledTaskRegistrar;
  9. import javax.annotation.PostConstruct;
  10. @Slf4j
  11. @Data
  12. @Configuration
  13. @ConfigurationProperties(prefix = "application.scheduler")
  14. public class SchedulingConfig implements SchedulingConfigurer {
  15. private int poolSize = 0;
  16. private boolean useSndIncident = true;
  17. private boolean useSndLog = true;
  18. @PostConstruct
  19. private void init() {
  20. log.info("[{}] ------------", this.getClass().getSimpleName());
  21. if (this.poolSize == 0) {
  22. log.warn("[{}] poolSize size set as default: {} EA.", this.getClass().getSimpleName(), this.poolSize);
  23. this.poolSize = 10;
  24. }
  25. log.info("[{}] poolCore: {} EA.", this.getClass().getSimpleName(), this.poolSize);
  26. }
  27. @Override
  28. public void configureTasks(ScheduledTaskRegistrar scheduledTaskRegistrar) {
  29. ThreadPoolTaskScheduler threadPoolTaskScheduler = new ThreadPoolTaskScheduler();
  30. threadPoolTaskScheduler.setPoolSize(this.poolSize);
  31. threadPoolTaskScheduler.setThreadNamePrefix("scheduler-");
  32. threadPoolTaskScheduler.initialize();
  33. scheduledTaskRegistrar.setTaskScheduler(threadPoolTaskScheduler);
  34. }
  35. }