It won't run. If you want it to run in the 28th in case of February, you have to create multiple CronExpressions for each case of days in month, and a trigger for each one, and then add all the triggers to your required Job.
This is what I have done:
CronExpressions creation:
public static List<CronExpression> getCronExpressionList(int seconds, int minutes,
int hours, int dayInMonth, Month month,
DayOfWeek dayOfWeek) {
final String monthsWith30Days = Month.APR + "," + Month.JUN + ","
+ Month.SEP + "," + Month.NOV;
List<CronExpression> crons = new LinkedList<CronExpression>();
String timeString = String.format(("%s %s %s "), seconds, minutes,
hours, 0, 0, 0);
String dateString = "%s %s %s";
String cron = null;
cron = timeString + String.format(dateString, dayInMonth, "*", "?");
crons.add(new CronExpression(cron));
if (dayInMonth > 28) {
String febCron = timeString + getFebruarLastDayDateString(dateString);
crons.add(new CronExpression(febCron));
if (dayInMonth == 31) {
String monthsWithThirtyDaysCron = timeString + String.format(dateString,
"L", monthsWith30Days, "?");
crons.add(new CronExpression(monthsWithThirtyDaysCron));
}
}
return crons;
}
private static String getFebruarLastDayDateString(String initialCron)
throws ParseException {
return String.format(initialCron, "L", Month.FEB, "?");
}
Trigger creation:
Set<CronTrigger> triggers = new HashSet<>();
int i = 1;
for (CronExpression cronEx : cronsList) {
CronTrigger trigger = newTrigger()
.withIdentity("trigger" + i, groupName)
.withSchedule(cronSchedule(cronEx))
.build();
triggers.add(trigger);
i++;
}