0

I am using springs CronTrigger class to build a trigger with following cron expression

0 10 12 ? 1/1 6#3

Which i think is a valid one that will schedule a Task to run on

Third friday of every month at 12:10 pm

This expression is giving expected output when I validated it on cronmaker.com.But while trying to build a trigger using this expression as:

CronTrigger trigger=new CronTrigger("0 10 12 ? 1/1 6#3");

Its throwing me java.lang.NumberFormatException For input string: "6#3".I am not getting what's gone wrong.

Dangling Piyush
  • 3,658
  • 8
  • 37
  • 52

2 Answers2

0

You should use org.springframework.scheduling.quartz.CronTriggerBean instead of CronTrigger.
Also your cron expression should be like this 0 10 12 ? * 6#3

Anubhab
  • 1,736
  • 2
  • 18
  • 28
  • I can't use CronTriggerBean because I am using ThreadPoolTaskScheduler which takes only Trigger and its implementations in schedule method.And I don't think 1/1 is a problem because i am building cron expression dynamically so it could be 1/2 1/3.And exception also occuring for the dayofWeek expression. – Dangling Piyush Mar 22 '13 at 09:58
  • Can you paste more code that you are doing related to this? I tried with my expression but in CrontriggerBean and it worked. – Anubhab Mar 22 '13 at 10:06
  • Also `CronTriggerBean` is a subclass of `CronTrigger`..So i don't think it would be a problem..see [this](http://static.springsource.org/spring/docs/2.0.x/api/org/springframework/scheduling/quartz/CronTriggerBean.html) – Anubhab Mar 22 '13 at 10:09
  • And check [this](http://www.coderanch.com/t/573160/Spring/Cron-expression-Spring-Task-scheduler) as well :) – Anubhab Mar 22 '13 at 10:13
  • I can't use CronTriggerBean because i am using org.springframework.scheduling.support.CronTrigger and why should i have to add all the quartz library for using just one class,That would be an overkill...Is there any other alternative? – Dangling Piyush Mar 22 '13 at 10:27
  • Then you need to change the cron expression dude..check [this](http://static.springsource.org/spring/docs/3.1.x/javadoc-api/org/springframework/scheduling/support/CronSequenceGenerator.html) out – Anubhab Mar 22 '13 at 10:32
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/26717/discussion-between-dangling-piyush-and-anubhab) – Dangling Piyush Mar 22 '13 at 10:43
0

I've just come with a workaround that should work. You can check it here - How to write Cron expression to execute a trigger on 3rd Sunday of every month at 11 PM?

Community
  • 1
  • 1
Bartserk
  • 675
  • 6
  • 18