[英]Spring Boot scheduler issue
I have a simple Spring Boot app that handles some REST API calls and so on.我有一个简单的 Spring Boot 应用程序,可以处理一些 REST API 调用等。 I added
@EnableScheduling
to my main class and then proceeded to add @Scheduled
on top of each function I need to schedule and then added a cron expression.我将
@EnableScheduling
添加到我的主类中,然后在我需要安排的每个函数之上添加@Scheduled
,然后添加了一个cron 表达式。
Spring boot Version : 2.7.1春季启动版本:2.7.1
What I have is the following:我所拥有的是以下内容:
I have three classes.我有三个班。 Each class contains a void function scheduled.
每个类都包含一个已调度的 void 函数。
I ran the app and everything seems working fine.我运行了该应用程序,一切似乎都运行良好。 All the API calls ran smoothly and as excepted, and then I ran the same app but from a jar file using the cmd.
所有的 API 调用都运行顺利,并且例外,然后我使用 cmd 从 jar 文件运行相同的应用程序。 The scheduler works fine the first day and then suddenly stops working and then starts working again the day after.
调度程序第一天工作正常,然后突然停止工作,然后第二天又开始工作。
I was monitoring the logs and it turned out that 4 out of 5 days the scheduler ran as expected, but skipped one day for no reason.我正在监视日志,结果发现调度程序在 5 天中有 4 天按预期运行,但无缘无故跳过了一天。
Any one might experienced this weird behavior?任何人都可能经历过这种奇怪的行为?
main class:主类:
@EnableScheduling
@SpringBootApplication
public class MYCLASSHERE {
public static void main(String[] args) {
SpringApplication.run(MYCLASSHERE.class, args);
}
}
each class has the following structure:每个类具有以下结构:
@Service
public class MYOTHERCLASS{
@Scheduled(cron = "0 5 12 * * *")
public void FUNCTION() {}
}
@Service
public class MYOTHERCLASS{
@Scheduled(cron = "0 10 12 * * *")
public void FUNCTION() {}
}
@Service
public class MYOTHERCLASS{
@Scheduled(cron = "0 15 12 * * *")
public void FUNCTION() {}
}
Note that everything is working fine.请注意,一切正常。 The scheduler stoppage that I'm experiencing is the only problem when running from a jar file.
从 jar 文件运行时,我遇到的调度程序停止是唯一的问题。
尝试 @Scheduled(cron = "0 35,40 14 * * ?") 为您的功能
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.