I have a Spring Boot application which will create a JAR file. In this application I have tow jobs to execute. One job is master job which saves data in MySQL database and second job perform some calculations and prepare some reports.
I need to execute master job at every 15 minutes and second job every 20 minute. So I used Spring Corn expression "* */15 * * * " for master job and " */20 * * * *" for second job. But the behavior of job execution is very abrupt. What I am doing wrong here?
New Answer You are correct , i personally tested its working fine
test the cron executions using below code in java
CronTrigger t = new CronTrigger("* */15 * * * * ");
TriggerContext tc = new SimpleTriggerContext();
System.out.println("Current Time:" + new Date()+ " |Next Execution " + t.nextExecutionTime(tc));
Calendar c = Calendar.getInstance();
c.setTime(new Date()); // Now use today date.
c.add(Calendar.MINUTE,16);
tc = new SimpleTriggerContext(c.getTime(),c.getTime(),c.getTime());
System.out.println("Current Time:" +c.getTime() + "Next Execution " + t.nextExecutionTime(tc));
c.add(Calendar.MINUTE,18);
tc = new SimpleTriggerContext(c.getTime(),c.getTime(),c.getTime());
System.out.println("Current Time:" + c.getTime() + "Next Execution " + t.nextExecutionTime(tc));
here are the imports
import org.springframework.scheduling.TriggerContext;
import org.springframework.scheduling.support.CronTrigger;
import org.springframework.scheduling.support.SimpleTriggerContext;
import java.util.Calendar;
import java.util.Date;
Old Answer
You wrongly scheduled 1st Job Every day at 3PM
the correct cron is */15 * * * *
using
@Scheduled(cron = "*/15 * * * *")
You wrongly scheduled second job at every day at 8PM
the correct cron is */20 * * * *
refer cron tab http://corntab.com/?c=*/20_*_*_*_*_
Try to use the following expression and make sure you have handled exception properly. 0 */15 * * * * - Use this expression to run job every 15 min 0 */20 * * * * -Use this expression to run job every 20 min
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With