3

I explored and found that in quartz cron expressions :

sec min hour day_of_month month day_of_week year, 

we can provide either day_of_month or day_of_week, but not both of them, as it's not implemented yet.

I want to run the scheduler after every two weeks and on MONDAY, THURSDAY, FRIDAY at 12 pm , then how can I achieve this.

providing following cron expression won't work:

* * 12 1/14 * MON, THU, FRI *

because we can't provide both day_of_week and day_of_month.

So, please let me know if there exists any other way of doing it, some other library etc. And I do not want to handle it in business logic rather simply using the cronexpression should suffice my needs.

gbhati
  • 493
  • 1
  • 8
  • 20

2 Answers2

0

try this site https://crontab.guru/ it may help you..

or http://www.corntab.com/?c=0_12___1,4,5

and for your question this will be that expression

0 12 * * 1,4,5

and for your understanding :

  +---------------- minute (0 - 59)
  |  +------------- hour (0 - 23)
  |  |  +---------- day of month (1 - 31)
  |  |  |  +------- month (1 - 12)
  |  |  |  |  +---- day of week (0 - 7) (Sunday=0 or 7)
  |  |  |  |  |
  0  12 *  * 1,4,5  command to be executed

Output:

“At 12:00 on Monday, Thursday, and Friday.”
next at 2016-12-15 12:00:00
then at 2016-12-16 12:00:00
then at 2016-12-19 12:00:00
then at 2016-12-22 12:00:00
then at 2016-12-23 12:00:00
.....
Shivkumar kondi
  • 6,458
  • 9
  • 31
  • 58
  • No sir, Actually the expression provided by you tells us only about scheduling the job on 1, 4, 5 Days. I want that it should repeat this cycle after every 4 days. – gbhati Dec 12 '16 at 12:59
  • @user2118745 no dear. its runs on every monday,thursday,friday at 12.00. I have just given comma separated list of weekdays(1,4,5). This goes on repeating for every week. – Shivkumar kondi Dec 12 '16 at 13:09
  • @user2118745 If you still have any doubt ,I can try to clarify it. and accept the answer if it helped in solving for problem. – Shivkumar kondi Dec 12 '16 at 13:31
  • Right sir, Now if I want to achieve like it should run after every two weeks on Monday, Thursday, and Friday starting from today. Then how to achieve that ? – gbhati Dec 13 '16 at 05:56
  • @user2118745 Its not that easy. For every week, we can use week values in list(0-7). you asking something odd which can be edited using month values in list(1-31) but those week days wont come that easy. U need to adjust this yourself. – Shivkumar kondi Dec 13 '16 at 06:00
  • @user2118745 Think so you got it now? – Shivkumar kondi Dec 13 '16 at 06:12
0

As far as I understood, you need such a query:

0 0 12 1-7,14-21 * MON,THU,FRI *

which means, that you will run your program from first to seven day of month, from fourteen to twenty one day of month but only if day of week is Monday, Thursday or Friday.

So the next occurence time will be:

2016-12-19T12:00:00+01:00
2017-01-02T12:00:00+01:00
2017-01-05T12:00:00+01:00
2017-01-06T12:00:00+01:00
....

the other question is, if the evaluator can handle such query correctly, you have to check it.

Puchacz
  • 1,987
  • 2
  • 24
  • 38