简体   繁体   中英

I am using this cron "0 0 9 * * ?" expression for scheduling task at morning 9am every day,

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(), "");
    });
}

}

Your cron should be this 0 9 * * * see cronguru for explanations

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM