首页 > 解决方案 > Spring调度程序运行两次

问题描述

我在 JBoss 中部署了主从应用程序,因此我的调度程序运行了两次。ShedLock不是我的问题的解决方案,因为电子邮件将触发直到用户停用过期的资产。所以我虽然检查请求是来自主机还是从机,并基于它运行我的代码,知道如何计算它或任何其他解决方案。谢谢我正在使用带有 MySQL db 的 Spring 4.x 和 REST Web 服务。

@Scheduled(cron = "${scheduler.i18n.crontime}")
public void getAssetNotification() {
    try {
        notificationDao.getAssetNotification(null);
    } catch (Exception e) {
        logger.error("getAssetNotification() - error in getAssetNotification", e);
    }
}

标签: javaspring-mvcjbossscheduled-tasks

解决方案


你不能只对数据库进行同步吗?

我发现了一个使用方面的旧代码片段:

Spring Scheduled Task 在集群环境中运行


推荐阅读