Quartz cron expression - last thursday of every month - spring

I am using Quartz Scheduling and Spring Batch and I need to run a particular job on the last Thursday of every month.
Is it possible to create such a Quartz cron expression?
Thanks,

Yes, Quartz has a special character -- L ("last") --, which allows you to define expressions such as the last friday of the month.
To fire a job at, say, 10am, on the last Thursday (5L) of every month, you can use the following cron expression:
0 0 10 ? * 5L

Related

How can I prevent a CA7 job with two schedule IDs from conflicting when they run on the same day?

I have a single job with two schedule ID’s. One runs the job the last day of the month and the other schid runs the last Sunday of the month. The problem I’m trying to correct arises when the last day of the month falls on a Sunday which causes a conflict between the two schedules.
My first thought was to split the two schids into two separate job names, while making one job a requirement for the other so they can’t run at the same time. The problem is this scenario would only apply on the rare days they both run and on all other days the requirement wouldn’t be met.
I’m not extremely familiar with ca7 so thought I’d look for some input. Can a schid be created with a conditional statement?
I think two schids will be needed. The options assume a calendar that specifies all days as processing days.
Option 1
Schid=1 schedules the job on the last Sunday of the month UNLESS that Sunday falls on the last day of the month.
Schid=2 schedules the job on the last day of the month.
ID=001 ROLL=N INDEX=+000
SCAL= DOTM=2000 LEADTM=0010 STARTM=1950
MONTHLY DAY=SUN WEEK=-00 MONTH=ALL
MONTHLY NRDAY=-00 MONTH=ALL
ID=002 ROLL=N INDEX=+000
SCAL= DOTM=2000 LEADTM=0010 STARTM=1950
MONTHLY RDAY=-00 MONTH=ALL
Option 2
Schid=1 runs the last day of the month unless that day falls on a Sunday.
Schid=2 runs on the last Sunday of the month.
ID=001 ROLL=D INDEX=+000
SCAL= DOTM=1300 LEADTM=0030 STARTM=1230
MONTHLY NDAY=SUN WEEK=-00 MONTH=ALL
MONTHLY RDAY=-00 MONTH=ALL
ID=002 ROLL=D INDEX=+000
SCAL= DOTM=1300 LEADTM=0030 STARTM=1230
MONTHLY DAY=SUN WEEK=-00 MONTH=ALL
Another approach is to define a separate calendar with precisely the days I want the job to run so the schedule definition is pretty simple.

How can i set Scheduler of Ibm on the first Monday of the week?

How can i set Scheduler of Ibm on the first Monday of the week? If i set DayOfMonth 1-7 and DayOfTheWeek 2 together receive an error. Is not good simbol as 2#1
The error is consistent with the documentation
https://www.ibm.com/docs/en/was-zos/8.5.5?topic=SS7K4U_8.5.5/com.ibm.websphere.javadoc.doc/web/apidocs/com/ibm/websphere/scheduler/UserCalendar.html
which states, "The day of week and day of month terms cannot be specified at the same time. One must be a '?' and the other a term."
Regarding your question, you asked about the "first Monday of the week". Did you mean first Monday of the month?
Here is an example of Monday of every week at 8am:
0 0 8 ? * MON
where the Scheduler cron terms are
second minute hourOfDay DayOfMonth Month DayOfWeek
If you want only the first Monday of the month, the Scheduler CRON doesn't have a way to do it.
An easy, but inefficient, solution would be to use the syntax for every Monday and have your task logic return immediately and skip itself if not a first Monday.
You also have the option of supplying your own UserCalendar implementation to implement customized scheduling:
https://www.ibm.com/docs/api/v1/content/SS7K4U_8.5.5/com.ibm.websphere.javadoc.doc/web/apidocs/com/ibm/websphere/scheduler/TaskInfo.html#setUserCalendar(java.lang.String,%20java.lang.String)

how to schedule to run a shell script on a particular day of a month

I want to schedule to run a shell script on a Thursday which comes after the second Tuesday of every month. How to schedule this in crontab?
The second Tuesday of the month will occur between the 8th and the 14th inclusive, so set the day-of-week field to 4 (Thursday), and the day-of-month field to 10-16 (that is, a range adjusted to be two days after the range of the month's second Tuesday).

spring cron jobs sceduler , monthly basis

What would be the spring cron-expression if I want to run a job in the last business day of the month.
Like if the month ends in sat-sun I need to fire it on Friday.
Business day includes Mon-Fri.
You need to use the LW expression see this: http://quartz-scheduler.org/documentation/quartz-1.x/tutorials/crontrigger
The 'L' and 'W' characters can also be combined in the day-of-month field
to yield 'LW', which translates to *"last weekday of the month"*.

Cron Expression to execute cron triggers on every week at 3 pm and start time from 5th April 2012

I am in need to create a cron triggers expression which should fire on every week at 3 pm and start time from 5th April 2012.
Please note i am using CronTriggerImpl
Thanks in advance.
By every week do you mean weekly? Using Quartz 2 API:
import org.quartz.CronScheduleBuilder.*;
MutableTrigger trigger = weeklyOnDayAndHourAndMinute(Calendar.THURSDAY, 15, 0).build()
trigger.setStartTime(new GregorianCalendar(2012, Calendar.APRIL, 5));
This will run the trigger every week on Thursday, 15:00, starting from April 5th.
Alternatively use a cron expression such as "0 0 15 * * THU" and set the start time to a date in the future.

Resources