java - Spring Boot 计划任务未运行
问题描述
我无法弄清楚为什么我的计划任务不会运行。我在那里读到的大多数帮助都说他们在入口类上缺少@EnableScheduling,或者在调度程序所在的组件上缺少@Component。我的代码中都有这两个,所以我无法弄清楚我在这里缺少什么。
更新: 我看到如果我注释掉 taskExecutor bean,它就会开始工作。如何维护我的任务执行器并使用调度器?
主要的
@SpringBootApplication
@EnableAutoConfiguration
@EnableAsync
@EnableScheduling
public class MonitoringApplication {
public static void main(String[] args) {
SpringApplication.run(MonitoringApplication.class, args);
}
@Bean
public Executor taskExecutor() {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setCorePoolSize(10);
executor.setMaxPoolSize(1000);
executor.setQueueCapacity(500);
executor.setThreadNamePrefix("async-thread-");
executor.initialize();
return executor;
}
@Configuration
public class WebConfiguration implements WebMvcConfigurer {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**").allowedMethods("*");
}
}
}
@Component
public class HealthMonitor {
ArrayList<Application> apps = new ArrayList<>();
HashMap<String, String> groupQuery = new HashMap<>();
@Autowired
MyMonitoringAdapter monitoringAdapter;
@Autowired
ServiceNowAdapter snowAdapter;
@Autowired
SitePinger sitePinger;
@PostConstruct
public void getAllAppHealth() {
System.out.println("Monitor starting up...");
buildAllApplications();
populateProductLine();
populateAppMonitors();
getIncidents();
System.out.println("Monitor started! - async processes may still be running");
}
@Scheduled(fixedRate = 1000)
public void scheduledRefresh() {
System.out.println("Fixed rate task async - ");
refreshPing();
}
}
解决方案
推荐阅读
- machine-learning - 如何在 python 中使用 GPU 制作自定义代码,同时使用 Pytorch 张量和矩阵函数
- ruby - Logstash 根据配置在特定字段上添加额外空间
- nagios - Nagios check_logfiles 插件 创建多个警报
- flutter - FittedBox 颤振
- julia - 提高 Julia 中 for 循环的速度
- javascript - 如何从异步 .map() 函数返回数据?
- c# - Visual Studio,调试随机在 mscorlib.dll 中抛出 SEHException 未处理的异常,没有 stackTrace
- akka - 如何从“外部”向分片 Akka 集群中的 Actor 发送命令?
- python - 网站上的文本不使用硒进行抓取
- reactjs - matril-ui如何按下纸张区域最底部的按钮