英文:
I am using this cron "0 0 9 * * ?" expression for scheduling task at morning 9am every day,
问题
但问题是任务会触发两次,一次在早上9点,另一次在下午2点30分,以下是我的代码
@Service
public class 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(), "");
});
}
}
英文:
but problem is that task is triggering two times, one at morning 9am and second one at 2:30 afternoon, below is my code
@Service
public class 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(), "");
});
}
}
答案1
得分: 2
你的定时任务应该是这样的 0 9 * * *
,详细解释请参考 cronguru。
英文:
Your cron should be this 0 9 * * *
see cronguru for explanations
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论