【问题标题】:I am using this cron "0 0 9 * * ?" expression for scheduling task at morning 9am every day,我正在使用这个 cron "0 0 9 * * ?"每天早上 9 点调度任务的表达式,
【发布时间】:2020-12-09 15:54:19
【问题描述】:

但问题是任务触发了两次,一次在早上 9 点,第二次在下午 2:30,下面是我的代码

@服务 公共类 NotificationScheduler {

@Autowired
private UsersService userService;

@Autowired
private SendSMS sendSms;

@Scheduled(cron = "0 0 9 * * ?")
public void sendSmsNotifictaion() {
    DecimalFormat deciFormat = new DecimalFormat(); 
    deciFormat.setMaximumFractionDigits(4);
    List<Users> userList=userService.getAllUserByIsNotSuAcc();
    userList.forEach(obj -> {
        String updatemsg="UPDATE:+Commission+Wallet+balance+for+"+obj.getName()+"+(AGENT+ID+"+obj.getId()+")+on+"+BaseDateUtil.getDateYYYYMMDD(new Date())+"+is+Rs.+"+deciFormat.format(BaseUtil.getDouble(obj.getBalance()))+".+Log+in+to+Spark+OMOB+to+view+and+transfer+balance.+Thank+you+for+your+trust+and+growth+with+us.+-+Spark+Team";
        sendSms.sendSMS(updatemsg, obj.getAgentmobil(), "");
    });
}

}

【问题讨论】:

  • 你读过那个语法的文档吗?

标签: java spring service cron scheduled-tasks


【解决方案1】:

您的 cron 应该是 0 9 * * *,请参阅 cronguru 了解说明

【讨论】:

    猜你喜欢
    • 2018-10-16
    • 2022-01-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-12
    • 1970-01-01
    • 2021-11-03
    相关资源
    最近更新 更多