1

I want to execute quartz scheduler every 2, 3, 4 ... etc day from today or user selected date. could anyone help me, what would be the cron expression for above requirement ?

user871611
  • 3,307
  • 7
  • 51
  • 73
  • Really. The [format for cron expressions](http://www.quartz-scheduler.org/documentation/quartz-2.x/tutorials/crontrigger.html#format) is very well documented. There are also tons of tutorials, examples, and documentations in the web. Why not simply look them up? – Seelenvirtuose Jan 30 '19 at 07:55
  • Thanks for your response but i visited lots of tutorials but did not find appropriate solution – prakash sharma Jan 30 '19 at 08:02
  • @Seelenvirtuose you're wrong. read the question more thoroughly. The **from today or user selected date**-part is pretty tricky (unsolvable?). – user871611 Jan 30 '19 at 08:12

3 Answers3

1

cron doesn't support scheduling "from today". It designed to survive restart so all schedules must be absolute.

talex
  • 17,973
  • 3
  • 29
  • 66
0

it triggers at 12 every third day..

0 0 12 1/3 * ? *

The next 5 schedules are :

  1. Thursday, January 31, 2019 12:00 PM
  2. Friday, February 1, 2019 12:00 PM
  3. Monday, February 4, 2019 12:00 PM
  4. Thursday, February 7, 2019 12:00 PM
  5. Sunday, February 10, 2019 12:00 PM

see Make Custom cron expression

Khalid Shah
  • 3,132
  • 3
  • 20
  • 39
0

Would this be what you're looking for:

CronScheduleBuilder scheduleBuilder = CronScheduleBuilder
          .cronSchedule(job.getCronExpression());

CronTrigger trigger = newTrigger()
.withIdentity(job.getTriggerName(),job.getTriggerGroup())
.startAt(job.getStartDate()) 
.withSchedule(scheduleBuilder).build();

scheduler.scheduleJob(jobDetail, trigger);

Hope that helps!

hd1
  • 33,938
  • 5
  • 80
  • 91
  • This only solves the start date issue. As @talex mentioned in his answer (correct me if I'm wrong in your setup), cron doesn't support *from day x*. – user871611 Jan 30 '19 at 14:06
  • Put it in a thread and [trigger it daily](https://stackoverflow.com/questions/20387881/how-to-run-certain-task-every-day-at-a-particular-time-using-scheduledexecutorse) and put a non-repeating job in on the thread? – hd1 Jan 31 '19 at 01:42