LS2
LS2

Reputation: 152

Cron expression to execute every 45 minutes and not 45th minute of the hour

I am trying to generate a cron expression which executes every 45 minutes.

I have created the following expression. 0 0/45 * 1/1 * ? *

But this expression fires every 45th minute of the hour. Ex: 10:45,11:00,11:45,12:00 etc.

But can we generate an expression which fires for example, 10:45,11:30,12:15 etc

Upvotes: 0

Views: 590

Answers (2)

Duong Anh
Duong Anh

Reputation: 557

The Cron expression does not support for every 45th minute. You can use with Trigger:

Trigger trigger = TriggerBuilder
                .newTrigger()
                .startAt(startTime)
                .withSchedule(
                        CalendarIntervalScheduleBuilder
                                .calendarIntervalSchedule()
                                .withIntervalInMinutes(45)
                                .withMisfireHandlingInstructionDoNothing())
                .build();

Upvotes: 2

iBug
iBug

Reputation: 37227

You can't do that directly.

0,45 */3 * * * ? *
30 1,4,7,10,13,16,19,22 * * * ? *
15 2,5,8,11,14,17,20,23 * * * ? *

Upvotes: 1

Related Questions