1

I want my cron job to run exactly at the below times. I am using Java, Spring, and Quartz.

6:30 Am, 9 AM, 12 PM, 2 PM

I tried below, not sure if its correct. Please let me know if this is correct:

0 30,0,0 6,9,12 * *

Here's my Spring XML snippet:

<bean id="test" class="org.springframework.scheduling.quartz.CronTriggerBean"> 
    <property name="jobDetail"> 
        <ref  bean="testjob"/> 
    </property> 
    <property name="cronExpression"> 
        <value>0 30,0,0 6,9,12 * * ?</value> 
    </property> 
</bean>
A Paul
  • 8,113
  • 3
  • 31
  • 61
  • 1
    In that line you say it should run at 6:00, 6:30, 9:00, 9:30, 12:00, 12:30. You probably want to make 2 lines for that, one with `30 6 * * ...` and `0 9,12,14 * * ....` – olivarra1 Aug 01 '14 at 13:45
  • would be good to get a bit more information - specifically the code that surrounds this. is it quartz or something else? are you using spring annotations. not all java crons are created equally. – dectarin Aug 01 '14 at 13:46
  • I am using spring.org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean – A Paul Aug 01 '14 at 13:47
  • ok but is it quartz for the cron? and is it annotation? – dectarin Aug 01 '14 at 13:48
  • Its quartz for the cron. – A Paul Aug 01 '14 at 13:50

1 Answers1

4

I would suggest you create these as 2 separate crons, one for the half past the hour ones and one for the on the hour ones.

so for 6:30 Am, 9 AM, 12 PM, 2 PM create the following two...

0 30 6 * * ? 

and

0 0 9,12,14 * * ?

Just to be sure you understand, you will need to create a second CronTriggerBean with the second cronExpression but you can reuse the job. The initial cron you tried would not work; you will need two cron expressions however you look at it.

durron597
  • 31,968
  • 17
  • 99
  • 158
dectarin
  • 986
  • 5
  • 15
  • +1 for the answer. Let me check if this works I will select this as answer. Thanks ! – A Paul Aug 01 '14 at 14:01
  • No problem, just to be sure you understand, you will need to create a second CronTriggerBean with the second cronExpression but you can reuse the job. The initial cron you tried would not work and could never work, you will need two cron expressions whatever you look at it :-/ – dectarin Aug 01 '14 at 14:07
  • +1, but your comment really ought to be in the main post to make sure future users see it. FIFY – durron597 Aug 01 '14 at 14:24
  • @durron597 thanks, that makes sense. I will ensure I take more care in future. – dectarin Aug 01 '14 at 14:26
  • @dectarin No problem, glad to see when lurkers begin to answer actively and well :) – durron597 Aug 01 '14 at 14:34