Cron Expression to run every Alternate Monday in Java CronJob - java

I've one Job running Every First Monday. I am using CronTrigger for that. My cron expression for existing job is as below.
0 0 0 ? * MON#1
Now, I want to change it to run on every alternate Monday of every Month.
Means on
1st Monday,
3rd Monday,
5th Monday like that.
my class for cron scheduler is
org.springframework.scheduling.quartz.CronTriggerBean

Related

Cron Expression for last working day or Friday

I have to create the batch job which will run on Fridays and last working day of the month.
I tried simple expression like "0 0 12 LW * 5" but its taking AND condition of (Last working day falling on Friday) while I need a OR condition like if its Friday or last weekday today then run the batch.
Can anyone please help with doing same with a cron expression ?

Creating a weekly Trigger which execute on particular days of week (Quartz Scheduler API)

I am trying to build a Trigger in Quartz Scheduler API 2.3.0 version which should get executed with the following criteria.
1.Start on particular date (Jan 25, 2021)
2.Start at predefined time (08.00.00 AM)
3.Once in every 2 weeks
4.On these particular days of week (Monday,Tuesday,Friday etc)
but I am confused how I should add the condition to execute this trigger on particular days of week
You could use this cron scheduling 0 8 * * 1,2,5.
It triggers at minute 0 at hour 8, at every day of the month and at every month, but only at the weekday 1,2 and 5 which are Monday, Tuesday and Friday respectively.
And for the biweekly scheduling i would count the weeks since 2021-01-25 and check if weeks % 2 == 0 and return from the task prematurely. Analogues for the starting date.

How to run quartz job for every working days of month

I need to run a job which needs to run first working day of each month, also i need to remove the holidays and get the first working day for each month.
FE : first of may is holiday, so that job needs to run on second day of may.
for the other jobs i use below code.
public CronTriggerFactoryBean testBean() {
CronTriggerFactoryBean bean = new CronTriggerFactoryBean();
bean.setJobDetail(test().getObject());
bean.setName("test");
bean.setGroup("test");
bean.setCronExpression("0 45 3 ? * *");
return bean;
}
Is there any way to solve this problem?
CRON doesn't and probably will never support any mechanism recognizing whether the holiday at the current or given location is. The holidays are inconsistent among countries and sometimes even among provinces (usually geographically large countries).
This feature would be very complicated for such simple-to-use designated expressions such as CRON is.
The only possible thing you can do to trigger every day from Monday to Friday (2-6) regardless of the holidays and perform some additional holiday check within the given job. In case the 2-6 or MON-FRI expression doesn't work, use 2,3,4,5,6.
bean.setCronExpression("0 45 3 ? * 2-6");
// At 03:45:00am, every day between Monday and Friday, every month
Disclaimer: CRON's week starts from Sunday (1).
Realizing that requirement via cron expression(s) would probably too complicated.
I would go with a cron expression that runs Monday to Friday, e. g.
0 3 45 * * MON-FRI
and check if the current day is a holiday inside the job by verifying against a list of dates.

Cron expression for the second to last day of week of the month

I want to trigger the second to last day of week of the month.
Typically, here is the last friday of the month (ex : 30/06/2017)
0 0 0 ? * FRIL
And I want the second to last (ex : 23/06/2017)
0 0 0 ? * FRIL-1
But this syntax return the same result as before (with the Quartz scheduler and with cronmaker)
The second to last day of week of the month can appear either the 3rd or the 4th week of the month.
So it's :
either : 0 0 0 ? * FRI#3
or : 0 0 0 ? * FRI#4
Do you have any advice ?
I don't think you can express that using cron syntax.
I can think of some work-arounds, though:
You could schedule your job every Friday and have some in-job logic to check whether it is actually the second-to-last before going on.
Another option would be to create a dummy cron trigger for the last Friday, retrieve the "next fire time", substract 7 days from that date and create the actual trigger using that exact date -- but you'd have to do that for every week (either by pre-scheduling several triggers, or by having your job re-schedule itself after each run).

CronScheduleBuilder in Quartz Scheduler in java

I am using Quartz Scheduler and i need to make a scheduler which will execute specific job at every three months into the program. so how do i make that cronExpression so i can do this things in java?
I need one month,Two month six month interval.
This expression is tested and works perfectly for quartz 2.2
"0 0 0 1 1/3 ?"
The above expression will fire every 3 months starting Jan 1st at 00:00 hours. Next will be on April 1st at 00:00 hrs.
for every 2 months use this
"0 0 0 1 1/2 ?"
You can change the first three zeros as you like. They refer to the time on the 1st of the month. The next number ,ie, "1" in my case is the date.

Categories

Resources