Reputation: 153
I need to trigger my mail every alternate Monday and Wednesday. I am using Java Spring in my application. I have try using this cron expression 00 15 11 ? * MONDAY#1
and same for Wednesday, but it is triggering on 1 Monday and Wednesday of the month. What I want is it should trigger on Monday and Wednesday of first, third and fifth week of each month.
Can someone please help me in creating this cron expression.
Upvotes: 0
Views: 1929
Reputation: 3056
All type of cron exrpession you build from website [Cron Maker]
I have one solution to meet with your requirement:
Algorithm:
1. Run cron every MON and WED day.
eg. 0 0 12 ? * MON,WED *
Start time Monday, September 7, 2015 6:10 AM Change
Next 5 scheduled dates
a. Monday, September 7, 2015 12:00 PM
b. Wednesday, September 9, 2015 12:00 PM
c. Monday, September 14, 2015 12:00 PM
d. Wednesday, September 16, 2015 12:00 PM
e. Monday, September 21, 2015 12:00 PM
2. Now pro-grammatically control on odd week. for eg in java
Calendar c = Calendar.getInstance();
if(c.get(Calendar.WEEK_OF_MONTH) % 2 != 0) {
//execute job
} else {
//not execute job just skip operation
}
if i am able to made actual cron then i will post it.
Upvotes: 1
Reputation: 81
What you want is
00 15 11 ? * MONDAY#1,MONDAY#3,MONDAY#5,WEDNESDAY#1,WEDNESDAY#3,WEDNESDAY#5"
but I don't think it's going to work, because with #, only one expression is allowed. So, you'll have to have multiple cron entries, like the following.
00 15 11 ? * MONDAY#1
00 15 11 ? * MONDAY#3
00 15 11 ? * MONDAY#5
00 15 11 ? * WEDNESDAY#1
00 15 11 ? * WEDNESDAY#3
00 15 11 ? * WEDNESDAY#5
Upvotes: 1