12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- package com.its.rota.server.config;
- import lombok.Data;
- import lombok.extern.slf4j.Slf4j;
- import org.springframework.boot.context.properties.ConfigurationProperties;
- import org.springframework.context.annotation.Configuration;
- import org.springframework.scheduling.annotation.SchedulingConfigurer;
- import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
- import org.springframework.scheduling.config.ScheduledTaskRegistrar;
- import javax.annotation.PostConstruct;
- @Slf4j
- @Data
- @Configuration
- @ConfigurationProperties(prefix = "application.scheduler")
- public class SchedulingConfig implements SchedulingConfigurer {
- private int poolSize = 0;
- private boolean useSndIncident = true;
- private boolean useSndLog = true;
- @PostConstruct
- private void init() {
- log.info("[{}] ------------", this.getClass().getSimpleName());
- if (this.poolSize == 0) {
- log.warn("[{}] poolSize size set as default: {} EA.", this.getClass().getSimpleName(), this.poolSize);
- this.poolSize = 10;
- }
- log.info("[{}] poolCore: {} EA.", this.getClass().getSimpleName(), this.poolSize);
- }
- @Override
- public void configureTasks(ScheduledTaskRegistrar scheduledTaskRegistrar) {
- ThreadPoolTaskScheduler threadPoolTaskScheduler = new ThreadPoolTaskScheduler();
- threadPoolTaskScheduler.setPoolSize(this.poolSize);
- threadPoolTaskScheduler.setThreadNamePrefix("scheduler-");
- threadPoolTaskScheduler.initialize();
- scheduledTaskRegistrar.setTaskScheduler(threadPoolTaskScheduler);
- }
- }
|