candy
candy

Reputation: 37

Scheduling with quartz every minute from 14:00 to 17:30

I am having problems scheduling my job with quartz... I cannot find an expression which lets me run my job from 14:00 to 17:30 every minute... I have tried this

0 0-30/1 14-17 ? * MON-FRI

but not works

Upvotes: 1

Views: 840

Answers (2)

Evgeniy Dorofeev
Evgeniy Dorofeev

Reputation: 136002

In Spring I would do it this way

@Scheduled(cron="0 0 14-16 * * *")
public void schedule1() {
    schedule2();
}

@Scheduled(cron="0 0-30 17 * * *")
public void schedule2() {
    System.out.println(new Date());
}

or in xml config

<bean id="test" class="test.Test" />

<task:scheduled-tasks>
    <task:scheduled ref="test" method="schedule2" cron="0 0 14-16 * * *"/>
    <task:scheduled ref="test" method="schedule2" cron="0 0-30 17 * * *"/>
</task:scheduled-tasks>

note that in xml config you can use one method. That trick with annotations was because we cannot use 2 annotations of the same type on one method.

Upvotes: 0

roger_that
roger_that

Reputation: 9791

You will have to create two Cron Expressions in order to achieve this.

  1. from 14:00 to 17:00
  2. 17:01 to 17:30

0 0/1 * 1/1 * ? * this is the cron expression for every minute. Apart from this refer http://www.cronmaker.com/ . With this you will be able to generate expressions.

Upvotes: 1

Related Questions