gpt4 book ai didi

java - Spring Boot App 运行两次预定作业

转载 作者:行者123 更新时间:2023-11-30 11:10:23 25 4
gpt4 key购买 nike

我的问题是预定方法“updateMembers”被调用了两次。我在谷歌上搜索了几个小时,发现问题可能是类 Scheduler 被初始化了两次,但我不知道如何解决这个问题。有什么建议吗?

@Configuration
@EnableScheduling
public class Scheduler {

@Autowired
PersistenceService persistenceService;

@Scheduled(cron = "* */15 * * * *")
public void updateMembers(){
try {
persistenceService.updateMembers();
}catch (IOException e){
Logger.getLogger(Application.class.getName())
.error("Scheduled updating of guildmembers failed due to: " + e.getMessage());
}
}

也许问题出在其他地方?在我的本地机器上没有发生这种行为。在我的网络服务器上,第二次调用在大约 47 秒后启动。该工作大约需要 2 分钟

最佳答案

用另一个 Cron 字符串解决了问题:cron = "0 */15 * * * *"

关于java - Spring Boot App 运行两次预定作业,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27689995/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com