How to know when will my Spring Boot scheduled job will trigger next time

Source: unsplash

Creating the CRON Expression

Let’s take a simple CRON Expression (“0 0 0 * * *”) which will get triggered every day at midnight.

Creating Sequence Generator

Now, we can use CronSequenceGenerator class present in the package to create a sequence generator instance. Let’s create an instance using its one of the constructor by providing the CRON expression we created in the last step.

Getting the next trigger point

Next, and the last step is to call next() by providing today’s date. This method will return a date object at which the CRON expression will get triggered.

Putting all in one plate

Let’s put everything togather into one code as below-

One Final Call

Sometime, getting only the next date will not be helpful and we want to generate next sequence of dates when your CRON expression will get triggered. We can tweak the above code as below to get as many sequences as we want.

Wolla, Now we gotta a way to get the next date and time when my CRON expression will be triggered.

A passionate software developer working on java, spring-boot and related technologies for more than 4 years.