From 80c5ba3968ac45b73158b60ca36d73acee7ced07 Mon Sep 17 00:00:00 2001 From: Carlos Garcia Date: Wed, 16 Oct 2024 15:23:57 +0200 Subject: [PATCH 01/18] refactor: replace while loop with enhanced for loop Signed-off-by: Carlos Garcia --- .../java/org/quartz/core/QuartzScheduler.java | 8 +- .../quartz/core/jmx/JobDataMapSupport.java | 4 +- .../quartz/impl/calendar/AnnualCalendar.java | 10 +-- .../listeners/BroadcastJobListener.java | 12 +-- .../listeners/BroadcastSchedulerListener.java | 80 +++++-------------- .../listeners/BroadcastTriggerListener.java | 18 ++--- .../xml/XMLSchedulingDataProcessorPlugin.java | 19 ++--- .../simpl/CascadingClassLoadHelper.java | 15 ++-- .../org/quartz/simpl/SimpleThreadPool.java | 10 +-- 9 files changed, 50 insertions(+), 126 deletions(-) diff --git a/quartz/src/main/java/org/quartz/core/QuartzScheduler.java b/quartz/src/main/java/org/quartz/core/QuartzScheduler.java index e5e0fa30b..a60fa424a 100644 --- a/quartz/src/main/java/org/quartz/core/QuartzScheduler.java +++ b/quartz/src/main/java/org/quartz/core/QuartzScheduler.java @@ -2340,17 +2340,13 @@ public boolean interrupt(String fireInstanceId) throws UnableToInterruptJobExcep } private void shutdownPlugins() { - java.util.Iterator itr = resources.getSchedulerPlugins().iterator(); - while (itr.hasNext()) { - SchedulerPlugin plugin = itr.next(); + for (SchedulerPlugin plugin : resources.getSchedulerPlugins()) { plugin.shutdown(); } } private void startPlugins() { - java.util.Iterator itr = resources.getSchedulerPlugins().iterator(); - while (itr.hasNext()) { - SchedulerPlugin plugin = itr.next(); + for (SchedulerPlugin plugin : resources.getSchedulerPlugins()) { plugin.start(); } } diff --git a/quartz/src/main/java/org/quartz/core/jmx/JobDataMapSupport.java b/quartz/src/main/java/org/quartz/core/jmx/JobDataMapSupport.java index 896d53cc3..5545d09f6 100644 --- a/quartz/src/main/java/org/quartz/core/jmx/JobDataMapSupport.java +++ b/quartz/src/main/java/org/quartz/core/jmx/JobDataMapSupport.java @@ -79,9 +79,7 @@ public static CompositeData toCompositeData(String key, String value) { public static TabularData toTabularData(JobDataMap jobDataMap) { TabularData tData = new TabularDataSupport(TABULAR_TYPE); ArrayList list = new ArrayList<>(); - Iterator iter = jobDataMap.keySet().iterator(); - while (iter.hasNext()) { - String key = iter.next(); + for (String key : jobDataMap.keySet()) { list.add(toCompositeData(key, String.valueOf(jobDataMap.get(key)))); } tData.putAll(list.toArray(new CompositeData[list.size()])); diff --git a/quartz/src/main/java/org/quartz/impl/calendar/AnnualCalendar.java b/quartz/src/main/java/org/quartz/impl/calendar/AnnualCalendar.java index d1829a749..099e82a03 100644 --- a/quartz/src/main/java/org/quartz/impl/calendar/AnnualCalendar.java +++ b/quartz/src/main/java/org/quartz/impl/calendar/AnnualCalendar.java @@ -104,10 +104,7 @@ public boolean isDayExcluded(java.util.Calendar day) { dataSorted = true; } - Iterator iter = excludeDays.iterator(); - while (iter.hasNext()) { - java.util.Calendar cl = (java.util.Calendar) iter.next(); - + for (java.util.Calendar cl : excludeDays) { // remember, the list is sorted if (dmonth < cl.get(java.util.Calendar.MONTH)) { return false; @@ -190,10 +187,7 @@ private void removeExcludedDay(java.util.Calendar day, boolean isChecked) { // Since there is no guarantee that the given day is in the arraylist with the exact same year // search for the object based on month and day of month in the list and remove it - Iterator iter = excludeDays.iterator(); - while (iter.hasNext()) { - java.util.Calendar cl = (java.util.Calendar) iter.next(); - + for (java.util.Calendar cl : excludeDays) { if (dmonth != cl.get(java.util.Calendar.MONTH)) { continue; } diff --git a/quartz/src/main/java/org/quartz/listeners/BroadcastJobListener.java b/quartz/src/main/java/org/quartz/listeners/BroadcastJobListener.java index fd37ea4e3..1069860f7 100644 --- a/quartz/src/main/java/org/quartz/listeners/BroadcastJobListener.java +++ b/quartz/src/main/java/org/quartz/listeners/BroadcastJobListener.java @@ -101,27 +101,21 @@ public List getListeners() { public void jobToBeExecuted(JobExecutionContext context) { - Iterator itr = listeners.iterator(); - while(itr.hasNext()) { - JobListener jl = itr.next(); + for (JobListener jl : listeners) { jl.jobToBeExecuted(context); } } public void jobExecutionVetoed(JobExecutionContext context) { - Iterator itr = listeners.iterator(); - while(itr.hasNext()) { - JobListener jl = itr.next(); + for (JobListener jl : listeners) { jl.jobExecutionVetoed(context); } } public void jobWasExecuted(JobExecutionContext context, JobExecutionException jobException) { - Iterator itr = listeners.iterator(); - while(itr.hasNext()) { - JobListener jl = itr.next(); + for (JobListener jl : listeners) { jl.jobWasExecuted(context, jobException); } } diff --git a/quartz/src/main/java/org/quartz/listeners/BroadcastSchedulerListener.java b/quartz/src/main/java/org/quartz/listeners/BroadcastSchedulerListener.java index 1e8c279a8..a29e2b2c4 100644 --- a/quartz/src/main/java/org/quartz/listeners/BroadcastSchedulerListener.java +++ b/quartz/src/main/java/org/quartz/listeners/BroadcastSchedulerListener.java @@ -56,162 +56,122 @@ public List getListeners() { } public void jobAdded(JobDetail jobDetail) { - Iterator itr = listeners.iterator(); - while(itr.hasNext()) { - SchedulerListener l = itr.next(); + for (SchedulerListener l : listeners) { l.jobAdded(jobDetail); } } public void jobDeleted(JobKey jobKey) { - Iterator itr = listeners.iterator(); - while(itr.hasNext()) { - SchedulerListener l = itr.next(); + for (SchedulerListener l : listeners) { l.jobDeleted(jobKey); } } public void jobScheduled(Trigger trigger) { - Iterator itr = listeners.iterator(); - while(itr.hasNext()) { - SchedulerListener l = itr.next(); + for (SchedulerListener l : listeners) { l.jobScheduled(trigger); } } public void jobUnscheduled(TriggerKey triggerKey) { - Iterator itr = listeners.iterator(); - while(itr.hasNext()) { - SchedulerListener l = itr.next(); + for (SchedulerListener l : listeners) { l.jobUnscheduled(triggerKey); } } public void triggerFinalized(Trigger trigger) { - Iterator itr = listeners.iterator(); - while(itr.hasNext()) { - SchedulerListener l = itr.next(); + for (SchedulerListener l : listeners) { l.triggerFinalized(trigger); } } public void triggerPaused(TriggerKey key) { - Iterator itr = listeners.iterator(); - while(itr.hasNext()) { - SchedulerListener l = itr.next(); + for (SchedulerListener l : listeners) { l.triggerPaused(key); } } public void triggersPaused(String triggerGroup) { - Iterator itr = listeners.iterator(); - while(itr.hasNext()) { - SchedulerListener l = itr.next(); + for (SchedulerListener l : listeners) { l.triggersPaused(triggerGroup); } } public void triggerResumed(TriggerKey key) { - Iterator itr = listeners.iterator(); - while(itr.hasNext()) { - SchedulerListener l = itr.next(); + for (SchedulerListener l : listeners) { l.triggerResumed(key); } } public void triggersResumed(String triggerGroup) { - Iterator itr = listeners.iterator(); - while(itr.hasNext()) { - SchedulerListener l = itr.next(); + for (SchedulerListener l : listeners) { l.triggersResumed(triggerGroup); } } public void schedulingDataCleared() { - Iterator itr = listeners.iterator(); - while(itr.hasNext()) { - SchedulerListener l = itr.next(); + for (SchedulerListener l : listeners) { l.schedulingDataCleared(); } } public void jobPaused(JobKey key) { - Iterator itr = listeners.iterator(); - while(itr.hasNext()) { - SchedulerListener l = itr.next(); + for (SchedulerListener l : listeners) { l.jobPaused(key); } } public void jobsPaused(String jobGroup) { - Iterator itr = listeners.iterator(); - while(itr.hasNext()) { - SchedulerListener l = itr.next(); + for (SchedulerListener l : listeners) { l.jobsPaused(jobGroup); } } public void jobResumed(JobKey key) { - Iterator itr = listeners.iterator(); - while(itr.hasNext()) { - SchedulerListener l = itr.next(); + for (SchedulerListener l : listeners) { l.jobResumed(key); } } public void jobsResumed(String jobGroup) { - Iterator itr = listeners.iterator(); - while(itr.hasNext()) { - SchedulerListener l = itr.next(); + for (SchedulerListener l : listeners) { l.jobsResumed(jobGroup); } } public void schedulerError(String msg, SchedulerException cause) { - Iterator itr = listeners.iterator(); - while(itr.hasNext()) { - SchedulerListener l = itr.next(); + for (SchedulerListener l : listeners) { l.schedulerError(msg, cause); } } public void schedulerStarted() { - Iterator itr = listeners.iterator(); - while(itr.hasNext()) { - SchedulerListener l = itr.next(); + for (SchedulerListener l : listeners) { l.schedulerStarted(); } } public void schedulerStarting() { - Iterator itr = listeners.iterator(); - while (itr.hasNext()) { - SchedulerListener l = itr.next(); + for (SchedulerListener l : listeners) { l.schedulerStarting(); } } public void schedulerInStandbyMode() { - Iterator itr = listeners.iterator(); - while(itr.hasNext()) { - SchedulerListener l = itr.next(); + for (SchedulerListener l : listeners) { l.schedulerInStandbyMode(); } } public void schedulerShutdown() { - Iterator itr = listeners.iterator(); - while(itr.hasNext()) { - SchedulerListener l = itr.next(); + for (SchedulerListener l : listeners) { l.schedulerShutdown(); } } public void schedulerShuttingdown() { - Iterator itr = listeners.iterator(); - while(itr.hasNext()) { - SchedulerListener l = itr.next(); + for (SchedulerListener l : listeners) { l.schedulerShuttingdown(); } } diff --git a/quartz/src/main/java/org/quartz/listeners/BroadcastTriggerListener.java b/quartz/src/main/java/org/quartz/listeners/BroadcastTriggerListener.java index 24532c07d..3e170e691 100644 --- a/quartz/src/main/java/org/quartz/listeners/BroadcastTriggerListener.java +++ b/quartz/src/main/java/org/quartz/listeners/BroadcastTriggerListener.java @@ -101,19 +101,15 @@ public List getListeners() { public void triggerFired(Trigger trigger, JobExecutionContext context) { - Iterator itr = listeners.iterator(); - while(itr.hasNext()) { - TriggerListener l = itr.next(); + for (TriggerListener l : listeners) { l.triggerFired(trigger, context); } } public boolean vetoJobExecution(Trigger trigger, JobExecutionContext context) { - Iterator itr = listeners.iterator(); - while(itr.hasNext()) { - TriggerListener l = itr.next(); - if(l.vetoJobExecution(trigger, context)) { + for (TriggerListener l : listeners) { + if (l.vetoJobExecution(trigger, context)) { return true; } } @@ -122,18 +118,14 @@ public boolean vetoJobExecution(Trigger trigger, JobExecutionContext context) { public void triggerMisfired(Trigger trigger) { - Iterator itr = listeners.iterator(); - while(itr.hasNext()) { - TriggerListener l = itr.next(); + for (TriggerListener l : listeners) { l.triggerMisfired(trigger); } } public void triggerComplete(Trigger trigger, JobExecutionContext context, CompletedExecutionInstruction triggerInstructionCode) { - Iterator itr = listeners.iterator(); - while(itr.hasNext()) { - TriggerListener l = itr.next(); + for (TriggerListener l : listeners) { l.triggerComplete(trigger, context, triggerInstructionCode); } } diff --git a/quartz/src/main/java/org/quartz/plugins/xml/XMLSchedulingDataProcessorPlugin.java b/quartz/src/main/java/org/quartz/plugins/xml/XMLSchedulingDataProcessorPlugin.java index b4cea901e..a41f53658 100644 --- a/quartz/src/main/java/org/quartz/plugins/xml/XMLSchedulingDataProcessorPlugin.java +++ b/quartz/src/main/java/org/quartz/plugins/xml/XMLSchedulingDataProcessorPlugin.java @@ -214,32 +214,29 @@ public void start(UserTransaction userTransaction) { if (scanInterval > 0) { getScheduler().getContext().put(JOB_INITIALIZATION_PLUGIN_NAME + '_' + getName(), this); } - - Iterator iterator = jobFiles.values().iterator(); - while (iterator.hasNext()) { - JobFile jobFile = iterator.next(); - + + for (JobFile jobFile : jobFiles.values()) { if (scanInterval > 0) { String jobTriggerName = buildJobTriggerName(jobFile.getFileBasename()); TriggerKey tKey = new TriggerKey(jobTriggerName, JOB_INITIALIZATION_PLUGIN_NAME); - + // remove preexisting job/trigger, if any getScheduler().unscheduleJob(tKey); JobDetail job = newJob().withIdentity(jobTriggerName, JOB_INITIALIZATION_PLUGIN_NAME).ofType(FileScanJob.class) - .usingJobData(FileScanJob.FILE_NAME, jobFile.getFileName()) - .usingJobData(FileScanJob.FILE_SCAN_LISTENER_NAME, JOB_INITIALIZATION_PLUGIN_NAME + '_' + getName()) - .build(); + .usingJobData(FileScanJob.FILE_NAME, jobFile.getFileName()) + .usingJobData(FileScanJob.FILE_SCAN_LISTENER_NAME, JOB_INITIALIZATION_PLUGIN_NAME + '_' + getName()) + .build(); SimpleTrigger trig = newTrigger().withIdentity(tKey).withSchedule( - simpleSchedule().repeatForever().withIntervalInMilliseconds(scanInterval)) + simpleSchedule().repeatForever().withIntervalInMilliseconds(scanInterval)) .forJob(job) .build(); getScheduler().scheduleJob(job, trig); getLog().debug("Scheduled file scan job for data file: {}, at interval: {}", jobFile.getFileName(), scanInterval); } - + processFile(jobFile); } } diff --git a/quartz/src/main/java/org/quartz/simpl/CascadingClassLoadHelper.java b/quartz/src/main/java/org/quartz/simpl/CascadingClassLoadHelper.java index a2d3666bc..0403915bf 100644 --- a/quartz/src/main/java/org/quartz/simpl/CascadingClassLoadHelper.java +++ b/quartz/src/main/java/org/quartz/simpl/CascadingClassLoadHelper.java @@ -107,9 +107,8 @@ public Class loadClass(String name) throws ClassNotFoundException { Class clazz = null; ClassLoadHelper loadHelper = null; - Iterator iter = loadHelpers.iterator(); - while (iter.hasNext()) { - loadHelper = iter.next(); + for (ClassLoadHelper helper : loadHelpers) { + loadHelper = helper; try { clazz = loadHelper.loadClass(name); @@ -161,9 +160,8 @@ public URL getResource(String name) { ClassLoadHelper loadHelper = null; - Iterator iter = loadHelpers.iterator(); - while (iter.hasNext()) { - loadHelper = iter.next(); + for (ClassLoadHelper helper : loadHelpers) { + loadHelper = helper; result = loadHelper.getResource(name); if (result != null) { @@ -197,9 +195,8 @@ public InputStream getResourceAsStream(String name) { ClassLoadHelper loadHelper = null; - Iterator iter = loadHelpers.iterator(); - while (iter.hasNext()) { - loadHelper = iter.next(); + for (ClassLoadHelper helper : loadHelpers) { + loadHelper = helper; result = loadHelper.getResourceAsStream(name); if (result != null) { diff --git a/quartz/src/main/java/org/quartz/simpl/SimpleThreadPool.java b/quartz/src/main/java/org/quartz/simpl/SimpleThreadPool.java index f38dfe590..4bfe34e06 100644 --- a/quartz/src/main/java/org/quartz/simpl/SimpleThreadPool.java +++ b/quartz/src/main/java/org/quartz/simpl/SimpleThreadPool.java @@ -270,9 +270,7 @@ public void initialize() throws SchedulerConfigException { } // create the worker threads and start them - Iterator workerThreads = createWorkerThreads(count).iterator(); - while(workerThreads.hasNext()) { - WorkerThread wt = workerThreads.next(); + for (WorkerThread wt : createWorkerThreads(count)) { wt.start(); availWorkers.add(wt); } @@ -332,9 +330,7 @@ public void shutdown(boolean waitForJobsToComplete) { return; // signal each worker thread to shut down - Iterator workerThreads = workers.iterator(); - while(workerThreads.hasNext()) { - WorkerThread wt = workerThreads.next(); + for (WorkerThread wt : workers) { wt.shutdown(); availWorkers.remove(wt); } @@ -371,7 +367,7 @@ public void shutdown(boolean waitForJobsToComplete) { } } - workerThreads = workers.iterator(); + Iterator workerThreads = workers.iterator(); while(workerThreads.hasNext()) { WorkerThread wt = (WorkerThread) workerThreads.next(); try { From 18ee16ebc95a91333808f6c10df69f3c10da174a Mon Sep 17 00:00:00 2001 From: Carlos Garcia Date: Wed, 16 Oct 2024 15:26:00 +0200 Subject: [PATCH 02/18] refactor: language migration; simplify maps operations Signed-off-by: Carlos Garcia --- .../java/org/quartz/simpl/RAMJobStore.java | 18 +++--------------- .../quartz/xml/XMLSchedulingDataProcessor.java | 6 +----- 2 files changed, 4 insertions(+), 20 deletions(-) diff --git a/quartz/src/main/java/org/quartz/simpl/RAMJobStore.java b/quartz/src/main/java/org/quartz/simpl/RAMJobStore.java index 65d463bce..1fe42bbac 100644 --- a/quartz/src/main/java/org/quartz/simpl/RAMJobStore.java +++ b/quartz/src/main/java/org/quartz/simpl/RAMJobStore.java @@ -280,11 +280,7 @@ public void storeJob(JobDetail newJob, if (!repl) { // get job group - HashMap grpMap = jobsByGroup.get(newJob.getKey().getGroup()); - if (grpMap == null) { - grpMap = new HashMap<>(100); - jobsByGroup.put(newJob.getKey().getGroup(), grpMap); - } + HashMap grpMap = jobsByGroup.computeIfAbsent(newJob.getKey().getGroup(), k -> new HashMap<>(100)); // add to jobs by group grpMap.put(newJob.getKey(), jw); // add to jobs by FQN map @@ -422,19 +418,11 @@ public void storeTrigger(OperableTrigger newTrigger, } // add to triggers by job - List jobList = triggersByJob.get(tw.jobKey); - if(jobList == null) { - jobList = new ArrayList<>(1); - triggersByJob.put(tw.jobKey, jobList); - } + List jobList = triggersByJob.computeIfAbsent(tw.jobKey, k -> new ArrayList<>(1)); jobList.add(tw); // add to triggers by group - HashMap grpMap = triggersByGroup.get(newTrigger.getKey().getGroup()); - if (grpMap == null) { - grpMap = new HashMap<>(100); - triggersByGroup.put(newTrigger.getKey().getGroup(), grpMap); - } + HashMap grpMap = triggersByGroup.computeIfAbsent(newTrigger.getKey().getGroup(), k -> new HashMap<>(100)); grpMap.put(newTrigger.getKey(), tw); // add to triggers by FQN map triggersByKey.put(tw.key, tw); diff --git a/quartz/src/main/java/org/quartz/xml/XMLSchedulingDataProcessor.java b/quartz/src/main/java/org/quartz/xml/XMLSchedulingDataProcessor.java index d737e321e..031591ffc 100644 --- a/quartz/src/main/java/org/quartz/xml/XMLSchedulingDataProcessor.java +++ b/quartz/src/main/java/org/quartz/xml/XMLSchedulingDataProcessor.java @@ -911,11 +911,7 @@ private Map> buildTriggersByFQJobNameMap(List> triggersByFQJobName = new HashMap<>(); for(MutableTrigger trigger: triggers) { - List triggersOfJob = triggersByFQJobName.get(trigger.getJobKey()); - if(triggersOfJob == null) { - triggersOfJob = new LinkedList<>(); - triggersByFQJobName.put(trigger.getJobKey(), triggersOfJob); - } + List triggersOfJob = triggersByFQJobName.computeIfAbsent(trigger.getJobKey(), k -> new LinkedList<>()); triggersOfJob.add(trigger); } From 29c79a135885404fe372f5ffd39142be644f31f6 Mon Sep 17 00:00:00 2001 From: Carlos Garcia Date: Wed, 16 Oct 2024 15:29:41 +0200 Subject: [PATCH 03/18] style: improve visibility change l by L for long literals Signed-off-by: Carlos Garcia --- quartz/src/main/java/org/quartz/DateBuilder.java | 8 ++++---- quartz/src/main/java/org/quartz/impl/QuartzServer.java | 2 +- .../main/java/org/quartz/impl/calendar/DailyCalendar.java | 2 +- .../org/quartz/impl/jdbcjobstore/JobStoreSupport.java | 4 ++-- .../org/quartz/impl/jdbcjobstore/StdJDBCDelegate.java | 2 +- .../java/org/quartz/impl/triggers/CronTriggerImpl.java | 6 +++--- quartz/src/main/java/org/quartz/simpl/RAMJobStore.java | 2 +- 7 files changed, 13 insertions(+), 13 deletions(-) diff --git a/quartz/src/main/java/org/quartz/DateBuilder.java b/quartz/src/main/java/org/quartz/DateBuilder.java index 0fb1f6b51..83a5bb10b 100644 --- a/quartz/src/main/java/org/quartz/DateBuilder.java +++ b/quartz/src/main/java/org/quartz/DateBuilder.java @@ -96,13 +96,13 @@ public enum IntervalUnit { MILLISECOND, SECOND, MINUTE, HOUR, DAY, WEEK, MONTH, public static final int DECEMBER = 12; - public static final long MILLISECONDS_IN_MINUTE = 60l * 1000l; + public static final long MILLISECONDS_IN_MINUTE = 60L * 1000L; - public static final long MILLISECONDS_IN_HOUR = 60l * 60l * 1000l; + public static final long MILLISECONDS_IN_HOUR = 60L * 60L * 1000L; - public static final long SECONDS_IN_MOST_DAYS = 24l * 60l * 60L; + public static final long SECONDS_IN_MOST_DAYS = 24L * 60L * 60L; - public static final long MILLISECONDS_IN_DAY = SECONDS_IN_MOST_DAYS * 1000l; + public static final long MILLISECONDS_IN_DAY = SECONDS_IN_MOST_DAYS * 1000L; private int month; private int day; diff --git a/quartz/src/main/java/org/quartz/impl/QuartzServer.java b/quartz/src/main/java/org/quartz/impl/QuartzServer.java index 284cefd3f..64ce13c8f 100644 --- a/quartz/src/main/java/org/quartz/impl/QuartzServer.java +++ b/quartz/src/main/java/org/quartz/impl/QuartzServer.java @@ -91,7 +91,7 @@ public void serve(SchedulerFactory schedFact, boolean console) sched.start(); try { - Thread.sleep(3000l); + Thread.sleep(3000L); } catch (Exception ignore) { } diff --git a/quartz/src/main/java/org/quartz/impl/calendar/DailyCalendar.java b/quartz/src/main/java/org/quartz/impl/calendar/DailyCalendar.java index 75531f663..5e5d0966c 100644 --- a/quartz/src/main/java/org/quartz/impl/calendar/DailyCalendar.java +++ b/quartz/src/main/java/org/quartz/impl/calendar/DailyCalendar.java @@ -538,7 +538,7 @@ public long getNextIncludedTime(long timeInMillis) { getTimeRangeEndingTimeInMillis(nextIncludedTime)) { //(move to start of next day) nextIncludedTime = getEndOfDayJavaCalendar(nextIncludedTime).getTime().getTime(); - nextIncludedTime += 1l; + nextIncludedTime += 1L; } else if ((getBaseCalendar() != null) && (!getBaseCalendar().isTimeIncluded(nextIncludedTime))){ nextIncludedTime = diff --git a/quartz/src/main/java/org/quartz/impl/jdbcjobstore/JobStoreSupport.java b/quartz/src/main/java/org/quartz/impl/jdbcjobstore/JobStoreSupport.java index 62b546cde..05c43b933 100644 --- a/quartz/src/main/java/org/quartz/impl/jdbcjobstore/JobStoreSupport.java +++ b/quartz/src/main/java/org/quartz/impl/jdbcjobstore/JobStoreSupport.java @@ -3978,11 +3978,11 @@ public void run() { } if (!shutdown) { - long timeToSleep = 50l; // At least a short pause to help balance threads + long timeToSleep = 50L; // At least a short pause to help balance threads if (!recoverMisfiredJobsResult.hasMoreMisfiredTriggers()) { timeToSleep = getMisfireThreshold() - (System.currentTimeMillis() - sTime); if (timeToSleep <= 0) { - timeToSleep = 50l; + timeToSleep = 50L; } if(numFails > 0) { diff --git a/quartz/src/main/java/org/quartz/impl/jdbcjobstore/StdJDBCDelegate.java b/quartz/src/main/java/org/quartz/impl/jdbcjobstore/StdJDBCDelegate.java index 134be39af..abac42981 100644 --- a/quartz/src/main/java/org/quartz/impl/jdbcjobstore/StdJDBCDelegate.java +++ b/quartz/src/main/java/org/quartz/impl/jdbcjobstore/StdJDBCDelegate.java @@ -2485,7 +2485,7 @@ public long selectNextFireTime(Connection conn) throws SQLException { if (rs.next()) { return rs.getLong(ALIAS_COL_NEXT_FIRE_TIME); } else { - return 0l; + return 0L; } } finally { closeResultSet(rs); diff --git a/quartz/src/main/java/org/quartz/impl/triggers/CronTriggerImpl.java b/quartz/src/main/java/org/quartz/impl/triggers/CronTriggerImpl.java index 5e7ac3459..2c298bee5 100644 --- a/quartz/src/main/java/org/quartz/impl/triggers/CronTriggerImpl.java +++ b/quartz/src/main/java/org/quartz/impl/triggers/CronTriggerImpl.java @@ -534,7 +534,7 @@ public Date getFireTimeAfter(Date afterTime) { } if (getStartTime().after(afterTime)) { - afterTime = new Date(getStartTime().getTime() - 1000l); + afterTime = new Date(getStartTime().getTime() - 1000L); } if (getEndTime() != null && (afterTime.compareTo(getEndTime()) >= 0)) { @@ -564,7 +564,7 @@ public Date getFireTimeAfter(Date afterTime) { public Date getFinalFireTime() { Date resultTime; if (getEndTime() != null) { - resultTime = getTimeBefore(new Date(getEndTime().getTime() + 1000l)); + resultTime = getTimeBefore(new Date(getEndTime().getTime() + 1000L)); } else { resultTime = (cronEx == null) ? null : cronEx.getFinalFireTime(); } @@ -780,7 +780,7 @@ public void updateWithNewCalendar(org.quartz.Calendar calendar, long misfireThre */ @Override public Date computeFirstFireTime(org.quartz.Calendar calendar) { - nextFireTime = getFireTimeAfter(new Date(getStartTime().getTime() - 1000l)); + nextFireTime = getFireTimeAfter(new Date(getStartTime().getTime() - 1000L)); while (nextFireTime != null && calendar != null && !calendar.isTimeIncluded(nextFireTime.getTime())) { diff --git a/quartz/src/main/java/org/quartz/simpl/RAMJobStore.java b/quartz/src/main/java/org/quartz/simpl/RAMJobStore.java index 1fe42bbac..2472a62df 100644 --- a/quartz/src/main/java/org/quartz/simpl/RAMJobStore.java +++ b/quartz/src/main/java/org/quartz/simpl/RAMJobStore.java @@ -105,7 +105,7 @@ public class RAMJobStore implements JobStore { protected final HashSet blockedJobs = new HashSet<>(); - protected long misfireThreshold = 5000l; + protected long misfireThreshold = 5000L; protected SchedulerSignaler signaler; From 088d1ebef3726629da4d6a58a8dee4f5ebac1929 Mon Sep 17 00:00:00 2001 From: Carlos Garcia Date: Wed, 16 Oct 2024 15:32:59 +0200 Subject: [PATCH 04/18] refactor: replace addAll() with parameterized constructor Signed-off-by: Carlos Garcia --- quartz/src/main/java/org/quartz/simpl/RAMJobStore.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/quartz/src/main/java/org/quartz/simpl/RAMJobStore.java b/quartz/src/main/java/org/quartz/simpl/RAMJobStore.java index 2472a62df..1844da626 100644 --- a/quartz/src/main/java/org/quartz/simpl/RAMJobStore.java +++ b/quartz/src/main/java/org/quartz/simpl/RAMJobStore.java @@ -1707,9 +1707,7 @@ protected String peekTriggers() { * @see org.quartz.spi.JobStore#getPausedTriggerGroups() */ public Set getPausedTriggerGroups() throws JobPersistenceException { - HashSet set = new HashSet<>(); - - set.addAll(pausedTriggerGroups); + HashSet set = new HashSet<>(pausedTriggerGroups); return set; } From a48536bf556fbef9031fe7c4488cb8c253ba91ef Mon Sep 17 00:00:00 2001 From: Carlos Garcia Date: Wed, 16 Oct 2024 15:36:10 +0200 Subject: [PATCH 05/18] refactor: set serialVersionUID fields as static and final Signed-off-by: Carlos Garcia --- .../src/main/java/org/quartz/impl/calendar/AnnualCalendar.java | 2 +- quartz/src/main/java/org/quartz/impl/calendar/BaseCalendar.java | 2 +- quartz/src/main/java/org/quartz/impl/calendar/CronCalendar.java | 2 +- .../src/main/java/org/quartz/impl/calendar/DailyCalendar.java | 2 +- .../src/main/java/org/quartz/impl/calendar/HolidayCalendar.java | 2 +- .../src/main/java/org/quartz/impl/calendar/MonthlyCalendar.java | 2 +- .../src/main/java/org/quartz/impl/calendar/WeeklyCalendar.java | 2 +- .../src/main/java/org/quartz/utils/StringKeyDirtyFlagMap.java | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/quartz/src/main/java/org/quartz/impl/calendar/AnnualCalendar.java b/quartz/src/main/java/org/quartz/impl/calendar/AnnualCalendar.java index 099e82a03..db1ec60aa 100644 --- a/quartz/src/main/java/org/quartz/impl/calendar/AnnualCalendar.java +++ b/quartz/src/main/java/org/quartz/impl/calendar/AnnualCalendar.java @@ -41,7 +41,7 @@ public class AnnualCalendar extends BaseCalendar implements Calendar, Serializable { - static final long serialVersionUID = 7346867105876610961L; + private static final long serialVersionUID = 7346867105876610961L; private ArrayList excludeDays = new ArrayList<>(); diff --git a/quartz/src/main/java/org/quartz/impl/calendar/BaseCalendar.java b/quartz/src/main/java/org/quartz/impl/calendar/BaseCalendar.java index eafc6d5ad..69740dc9d 100644 --- a/quartz/src/main/java/org/quartz/impl/calendar/BaseCalendar.java +++ b/quartz/src/main/java/org/quartz/impl/calendar/BaseCalendar.java @@ -46,7 +46,7 @@ */ public class BaseCalendar implements Calendar, Serializable, Cloneable { - static final long serialVersionUID = 3106623404629760239L; + private static final long serialVersionUID = 3106623404629760239L; //

A optional base calendar.

private Calendar baseCalendar; diff --git a/quartz/src/main/java/org/quartz/impl/calendar/CronCalendar.java b/quartz/src/main/java/org/quartz/impl/calendar/CronCalendar.java index 0b827489a..5160968a0 100644 --- a/quartz/src/main/java/org/quartz/impl/calendar/CronCalendar.java +++ b/quartz/src/main/java/org/quartz/impl/calendar/CronCalendar.java @@ -24,7 +24,7 @@ * @author Aaron Craven */ public class CronCalendar extends BaseCalendar { - static final long serialVersionUID = -8172103999750856831L; + private static final long serialVersionUID = -8172103999750856831L; CronExpression cronExpression; diff --git a/quartz/src/main/java/org/quartz/impl/calendar/DailyCalendar.java b/quartz/src/main/java/org/quartz/impl/calendar/DailyCalendar.java index 5e5d0966c..669d6c106 100644 --- a/quartz/src/main/java/org/quartz/impl/calendar/DailyCalendar.java +++ b/quartz/src/main/java/org/quartz/impl/calendar/DailyCalendar.java @@ -27,7 +27,7 @@ * @author Mike Funk, Aaron Craven */ public class DailyCalendar extends BaseCalendar { - static final long serialVersionUID = -7561220099904944039L; + private static final long serialVersionUID = -7561220099904944039L; private static final String invalidHourOfDay = "Invalid hour of day: "; private static final String invalidMinute = "Invalid minute: "; diff --git a/quartz/src/main/java/org/quartz/impl/calendar/HolidayCalendar.java b/quartz/src/main/java/org/quartz/impl/calendar/HolidayCalendar.java index f172e43e8..eed6b6eff 100644 --- a/quartz/src/main/java/org/quartz/impl/calendar/HolidayCalendar.java +++ b/quartz/src/main/java/org/quartz/impl/calendar/HolidayCalendar.java @@ -44,7 +44,7 @@ */ public class HolidayCalendar extends BaseCalendar implements Calendar, Serializable { - static final long serialVersionUID = -7590908752291814693L; + private static final long serialVersionUID = -7590908752291814693L; // A sorted set to store the holidays private TreeSet dates = new TreeSet<>(); diff --git a/quartz/src/main/java/org/quartz/impl/calendar/MonthlyCalendar.java b/quartz/src/main/java/org/quartz/impl/calendar/MonthlyCalendar.java index d3383005d..401933830 100644 --- a/quartz/src/main/java/org/quartz/impl/calendar/MonthlyCalendar.java +++ b/quartz/src/main/java/org/quartz/impl/calendar/MonthlyCalendar.java @@ -38,7 +38,7 @@ public class MonthlyCalendar extends BaseCalendar implements Calendar, Serializable { - static final long serialVersionUID = 419164961091807944L; + private static final long serialVersionUID = 419164961091807944L; private static final int MAX_DAYS_IN_MONTH = 31; diff --git a/quartz/src/main/java/org/quartz/impl/calendar/WeeklyCalendar.java b/quartz/src/main/java/org/quartz/impl/calendar/WeeklyCalendar.java index e98eefa65..817d8797e 100644 --- a/quartz/src/main/java/org/quartz/impl/calendar/WeeklyCalendar.java +++ b/quartz/src/main/java/org/quartz/impl/calendar/WeeklyCalendar.java @@ -37,7 +37,7 @@ */ public class WeeklyCalendar extends BaseCalendar implements Calendar, Serializable { - static final long serialVersionUID = -6809298821229007586L; + private static final long serialVersionUID = -6809298821229007586L; // An array to store the week days which are to be excluded. // java.util.Calendar.MONDAY etc. are used as index. diff --git a/quartz/src/main/java/org/quartz/utils/StringKeyDirtyFlagMap.java b/quartz/src/main/java/org/quartz/utils/StringKeyDirtyFlagMap.java index 7307b17e8..93f563ad1 100644 --- a/quartz/src/main/java/org/quartz/utils/StringKeyDirtyFlagMap.java +++ b/quartz/src/main/java/org/quartz/utils/StringKeyDirtyFlagMap.java @@ -30,7 +30,7 @@ *

*/ public class StringKeyDirtyFlagMap extends DirtyFlagMap { - static final long serialVersionUID = -9076749120524952280L; + private static final long serialVersionUID = -9076749120524952280L; /** * @deprecated JDBCJobStores no longer prune out transient data. If you From 83195efb0c3c457b5e13fb00c11319ef2af8199f Mon Sep 17 00:00:00 2001 From: Carlos Garcia Date: Wed, 16 Oct 2024 15:43:28 +0200 Subject: [PATCH 06/18] refactor: language migration, remove unnecessary boxing Signed-off-by: Carlos Garcia --- quartz-jobs/build.gradle | 2 +- .../org/quartz/core/QuartzSchedulerMBeanImpl.java | 11 ++++------- .../quartz/ee/servlet/QuartzInitializerListener.java | 6 +++--- .../quartz/ee/servlet/QuartzInitializerServlet.java | 6 +++--- .../java/org/quartz/impl/StdSchedulerFactory.java | 10 +++++----- .../quartz/impl/jdbcjobstore/JobStoreSupport.java | 2 +- .../oracle/weblogic/WebLogicOracleDelegate.java | 4 ++-- .../plugins/history/LoggingJobHistoryPlugin.java | 8 ++++---- .../plugins/history/LoggingTriggerHistoryPlugin.java | 4 ++-- .../org/quartz/simpl/PropertySettingJobFactory.java | 2 +- .../main/java/org/quartz/utils/PropertiesParser.java | 2 +- .../java/org/quartz/utils/StringKeyDirtyFlagMap.java | 12 ++++++------ 12 files changed, 33 insertions(+), 36 deletions(-) diff --git a/quartz-jobs/build.gradle b/quartz-jobs/build.gradle index 2fce21b09..73c3d8d39 100644 --- a/quartz-jobs/build.gradle +++ b/quartz-jobs/build.gradle @@ -29,7 +29,7 @@ java { } test { - maxParallelForks 1 + maxParallelForks 10 forkEvery 1 } diff --git a/quartz/src/main/java/org/quartz/core/QuartzSchedulerMBeanImpl.java b/quartz/src/main/java/org/quartz/core/QuartzSchedulerMBeanImpl.java index c238bc7b0..8cb06a504 100644 --- a/quartz/src/main/java/org/quartz/core/QuartzSchedulerMBeanImpl.java +++ b/quartz/src/main/java/org/quartz/core/QuartzSchedulerMBeanImpl.java @@ -982,7 +982,7 @@ public void setSampledStatisticsEnabled(boolean enabled) { this.sampledStatistics.shutdown(); this.sampledStatistics = NULL_SAMPLED_STATISTICS; } - sendNotification(SAMPLED_STATISTICS_ENABLED, Boolean.valueOf(enabled)); + sendNotification(SAMPLED_STATISTICS_ENABLED, enabled); } } @@ -1000,12 +1000,9 @@ public long getJobsScheduledMostRecentSample() { public Map getPerformanceMetrics() { Map result = new HashMap<>(); - result.put("JobsCompleted", Long - .valueOf(getJobsCompletedMostRecentSample())); - result.put("JobsExecuted", Long - .valueOf(getJobsExecutedMostRecentSample())); - result.put("JobsScheduled", Long - .valueOf(getJobsScheduledMostRecentSample())); + result.put("JobsCompleted", getJobsCompletedMostRecentSample()); + result.put("JobsExecuted", getJobsExecutedMostRecentSample()); + result.put("JobsScheduled", getJobsScheduledMostRecentSample()); return result; } } diff --git a/quartz/src/main/java/org/quartz/ee/servlet/QuartzInitializerListener.java b/quartz/src/main/java/org/quartz/ee/servlet/QuartzInitializerListener.java index ad36c886a..301e02e81 100644 --- a/quartz/src/main/java/org/quartz/ee/servlet/QuartzInitializerListener.java +++ b/quartz/src/main/java/org/quartz/ee/servlet/QuartzInitializerListener.java @@ -156,11 +156,11 @@ public void contextInitialized(ServletContextEvent sce) { if(shutdownPref == null) shutdownPref = servletContext.getInitParameter("shutdown-on-unload"); if (shutdownPref != null) { - performShutdown = Boolean.valueOf(shutdownPref); + performShutdown = Boolean.parseBoolean(shutdownPref); } String shutdownWaitPref = servletContext.getInitParameter("quartz:wait-on-shutdown"); if (shutdownWaitPref != null) { - waitOnShutdown = Boolean.valueOf(shutdownWaitPref); + waitOnShutdown = Boolean.parseBoolean(shutdownWaitPref); } factory = getSchedulerFactory(configFile); @@ -191,7 +191,7 @@ public void contextInitialized(ServletContextEvent sce) { * the scheduler will be started. This is to maintain backwards * compatability. */ - if (startOnLoad == null || (Boolean.valueOf(startOnLoad))) { + if (startOnLoad == null || (Boolean.parseBoolean(startOnLoad))) { if(startDelay <= 0) { // Start now scheduler.start(); diff --git a/quartz/src/main/java/org/quartz/ee/servlet/QuartzInitializerServlet.java b/quartz/src/main/java/org/quartz/ee/servlet/QuartzInitializerServlet.java index 1614966bd..7e43902b6 100644 --- a/quartz/src/main/java/org/quartz/ee/servlet/QuartzInitializerServlet.java +++ b/quartz/src/main/java/org/quartz/ee/servlet/QuartzInitializerServlet.java @@ -172,11 +172,11 @@ public void init(ServletConfig cfg) throws jakarta.servlet.ServletException { String shutdownPref = cfg.getInitParameter("shutdown-on-unload"); if (shutdownPref != null) { - performShutdown = Boolean.valueOf(shutdownPref); + performShutdown = Boolean.parseBoolean(shutdownPref); } String shutdownWaitPref = cfg.getInitParameter("wait-on-shutdown"); if (shutdownPref != null) { - waitOnShutdown = Boolean.valueOf(shutdownWaitPref); + waitOnShutdown = Boolean.parseBoolean(shutdownWaitPref); } factory = getSchedulerFactory(configFile); @@ -204,7 +204,7 @@ public void init(ServletConfig cfg) throws jakarta.servlet.ServletException { * the scheduler will be started. This is to maintain backwards * compatability. */ - if (startOnLoad == null || (Boolean.valueOf(startOnLoad))) { + if (startOnLoad == null || (Boolean.parseBoolean(startOnLoad))) { if(startDelay <= 0) { // Start now scheduler.start(); diff --git a/quartz/src/main/java/org/quartz/impl/StdSchedulerFactory.java b/quartz/src/main/java/org/quartz/impl/StdSchedulerFactory.java index 7323505aa..650c463fb 100644 --- a/quartz/src/main/java/org/quartz/impl/StdSchedulerFactory.java +++ b/quartz/src/main/java/org/quartz/impl/StdSchedulerFactory.java @@ -1475,15 +1475,15 @@ private void setBeanProps(Object obj, Properties props) refName = name; if (params[0].equals(int.class)) { - setMeth.invoke(obj, new Object[]{Integer.valueOf(refProps.getIntProperty(refName))}); + setMeth.invoke(obj, new Object[]{refProps.getIntProperty(refName)}); } else if (params[0].equals(long.class)) { - setMeth.invoke(obj, new Object[]{Long.valueOf(refProps.getLongProperty(refName))}); + setMeth.invoke(obj, new Object[]{refProps.getLongProperty(refName)}); } else if (params[0].equals(float.class)) { - setMeth.invoke(obj, new Object[]{Float.valueOf(refProps.getFloatProperty(refName))}); + setMeth.invoke(obj, new Object[]{refProps.getFloatProperty(refName)}); } else if (params[0].equals(double.class)) { - setMeth.invoke(obj, new Object[]{Double.valueOf(refProps.getDoubleProperty(refName))}); + setMeth.invoke(obj, new Object[]{refProps.getDoubleProperty(refName)}); } else if (params[0].equals(boolean.class)) { - setMeth.invoke(obj, new Object[]{Boolean.valueOf(refProps.getBooleanProperty(refName))}); + setMeth.invoke(obj, new Object[]{refProps.getBooleanProperty(refName)}); } else if (params[0].equals(String.class)) { setMeth.invoke(obj, new Object[]{refProps.getStringProperty(refName)}); } else { diff --git a/quartz/src/main/java/org/quartz/impl/jdbcjobstore/JobStoreSupport.java b/quartz/src/main/java/org/quartz/impl/jdbcjobstore/JobStoreSupport.java index 05c43b933..7b6bae415 100644 --- a/quartz/src/main/java/org/quartz/impl/jdbcjobstore/JobStoreSupport.java +++ b/quartz/src/main/java/org/quartz/impl/jdbcjobstore/JobStoreSupport.java @@ -221,7 +221,7 @@ public void setUseProperties(String useProp) { useProp = "false"; } - this.useProperties = Boolean.valueOf(useProp); + this.useProperties = Boolean.parseBoolean(useProp); } /** diff --git a/quartz/src/main/java/org/quartz/impl/jdbcjobstore/oracle/weblogic/WebLogicOracleDelegate.java b/quartz/src/main/java/org/quartz/impl/jdbcjobstore/oracle/weblogic/WebLogicOracleDelegate.java index 664b73fa8..f450e36ca 100644 --- a/quartz/src/main/java/org/quartz/impl/jdbcjobstore/oracle/weblogic/WebLogicOracleDelegate.java +++ b/quartz/src/main/java/org/quartz/impl/jdbcjobstore/oracle/weblogic/WebLogicOracleDelegate.java @@ -55,13 +55,13 @@ protected Blob writeDataToBlob(ResultSet rs, int column, byte[] data) throws SQL try { // try to find putBytes method... Method m = blob.getClass().getMethod("putBytes", new Class[] {long.class, byte[].class}); - m.invoke(blob, new Object[] {new Long(1), data}); + m.invoke(blob, new Object[] {1L, data}); } catch (Exception e) { try { // Added this logic to the original code from OpenSymphony // putBytes method does not exist. Try setBytes Method m = blob.getClass().getMethod("setBytes", new Class[] { long.class, byte[].class }); - m.invoke(blob, new Object[] { new Long(1), data }); + m.invoke(blob, new Object[] {1L, data }); } catch (Exception e2) { throw new SQLException("Unable to find putBytes(long,byte[]) or setBytes(long,byte[]) methods on blob: " + e2); } diff --git a/quartz/src/main/java/org/quartz/plugins/history/LoggingJobHistoryPlugin.java b/quartz/src/main/java/org/quartz/plugins/history/LoggingJobHistoryPlugin.java index b7dab0e5f..647f2dc10 100644 --- a/quartz/src/main/java/org/quartz/plugins/history/LoggingJobHistoryPlugin.java +++ b/quartz/src/main/java/org/quartz/plugins/history/LoggingJobHistoryPlugin.java @@ -463,7 +463,7 @@ public void jobToBeExecuted(JobExecutionContext context) { context.getJobDetail().getKey().getGroup(), new java.util.Date(), trigger.getKey().getName(), trigger.getKey().getGroup(), trigger.getPreviousFireTime(), trigger.getNextFireTime(), - Integer.valueOf(context.getRefireCount()) + context.getRefireCount() }; getLog().info(MessageFormat.format(getJobToBeFiredMessage(), args)); @@ -491,7 +491,7 @@ public void jobWasExecuted(JobExecutionContext context, context.getJobDetail().getKey().getGroup(), new java.util.Date(), trigger.getKey().getName(), trigger.getKey().getGroup(), trigger.getPreviousFireTime(), trigger.getNextFireTime(), - Integer.valueOf(context.getRefireCount()), errMsg + context.getRefireCount(), errMsg }; getLog().warn(MessageFormat.format(getJobFailedMessage(), args), jobException); @@ -507,7 +507,7 @@ public void jobWasExecuted(JobExecutionContext context, context.getJobDetail().getKey().getGroup(), new java.util.Date(), trigger.getKey().getName(), trigger.getKey().getGroup(), trigger.getPreviousFireTime(), trigger.getNextFireTime(), - Integer.valueOf(context.getRefireCount()), result + context.getRefireCount(), result }; getLog().info(MessageFormat.format(getJobSuccessMessage(), args)); @@ -530,7 +530,7 @@ public void jobExecutionVetoed(JobExecutionContext context) { context.getJobDetail().getKey().getGroup(), new java.util.Date(), trigger.getKey().getName(), trigger.getKey().getGroup(), trigger.getPreviousFireTime(), trigger.getNextFireTime(), - Integer.valueOf(context.getRefireCount()) + context.getRefireCount() }; getLog().info(MessageFormat.format(getJobWasVetoedMessage(), args)); diff --git a/quartz/src/main/java/org/quartz/plugins/history/LoggingTriggerHistoryPlugin.java b/quartz/src/main/java/org/quartz/plugins/history/LoggingTriggerHistoryPlugin.java index ac6b06372..977c5c518 100644 --- a/quartz/src/main/java/org/quartz/plugins/history/LoggingTriggerHistoryPlugin.java +++ b/quartz/src/main/java/org/quartz/plugins/history/LoggingTriggerHistoryPlugin.java @@ -381,7 +381,7 @@ public void triggerFired(Trigger trigger, JobExecutionContext context) { trigger.getPreviousFireTime(), trigger.getNextFireTime(), new java.util.Date(), context.getJobDetail().getKey().getName(), context.getJobDetail().getKey().getGroup(), - Integer.valueOf(context.getRefireCount()) + context.getRefireCount() }; getLog().info(MessageFormat.format(getTriggerFiredMessage(), args)); @@ -426,7 +426,7 @@ public void triggerComplete(Trigger trigger, JobExecutionContext context, trigger.getPreviousFireTime(), trigger.getNextFireTime(), new java.util.Date(), context.getJobDetail().getKey().getName(), context.getJobDetail().getKey().getGroup(), - Integer.valueOf(context.getRefireCount()), + context.getRefireCount(), triggerInstructionCode.toString(), instrCode }; diff --git a/quartz/src/main/java/org/quartz/simpl/PropertySettingJobFactory.java b/quartz/src/main/java/org/quartz/simpl/PropertySettingJobFactory.java index f5626660d..03aa8e8ad 100644 --- a/quartz/src/main/java/org/quartz/simpl/PropertySettingJobFactory.java +++ b/quartz/src/main/java/org/quartz/simpl/PropertySettingJobFactory.java @@ -171,7 +171,7 @@ protected void setBeanProps(Object obj, JobDataMap data) throws SchedulerExcepti if (o instanceof String) { String str = (String) o; if (str.length() == 1) { - parm = Character.valueOf(str.charAt(0)); + parm = str.charAt(0); } } else if (o instanceof Character) { parm = o; diff --git a/quartz/src/main/java/org/quartz/utils/PropertiesParser.java b/quartz/src/main/java/org/quartz/utils/PropertiesParser.java index c94189c52..64734099c 100644 --- a/quartz/src/main/java/org/quartz/utils/PropertiesParser.java +++ b/quartz/src/main/java/org/quartz/utils/PropertiesParser.java @@ -122,7 +122,7 @@ public boolean getBooleanProperty(String name) { public boolean getBooleanProperty(String name, boolean def) { String val = getStringProperty(name); - return (val == null) ? def : Boolean.valueOf(val); + return (val == null) ? def : Boolean.parseBoolean(val); } public byte getByteProperty(String name) throws NumberFormatException { diff --git a/quartz/src/main/java/org/quartz/utils/StringKeyDirtyFlagMap.java b/quartz/src/main/java/org/quartz/utils/StringKeyDirtyFlagMap.java index 93f563ad1..afb3a610d 100644 --- a/quartz/src/main/java/org/quartz/utils/StringKeyDirtyFlagMap.java +++ b/quartz/src/main/java/org/quartz/utils/StringKeyDirtyFlagMap.java @@ -180,7 +180,7 @@ public void removeTransientData() { *

*/ public void put(String key, int value) { - super.put(key, Integer.valueOf(value)); + super.put(key, value); } /** @@ -189,7 +189,7 @@ public void put(String key, int value) { *

*/ public void put(String key, long value) { - super.put(key, Long.valueOf(value)); + super.put(key, value); } /** @@ -198,7 +198,7 @@ public void put(String key, long value) { *

*/ public void put(String key, float value) { - super.put(key, Float.valueOf(value)); + super.put(key, value); } /** @@ -207,7 +207,7 @@ public void put(String key, float value) { *

*/ public void put(String key, double value) { - super.put(key, Double.valueOf(value)); + super.put(key, value); } /** @@ -216,7 +216,7 @@ public void put(String key, double value) { *

*/ public void put(String key, boolean value) { - super.put(key, Boolean.valueOf(value)); + super.put(key, value); } /** @@ -225,7 +225,7 @@ public void put(String key, boolean value) { *

*/ public void put(String key, char value) { - super.put(key, Character.valueOf(value)); + super.put(key, value); } /** From e51578ff74f08d5b9982bc0d139c171098265bdc Mon Sep 17 00:00:00 2001 From: Carlos Garcia Date: Wed, 16 Oct 2024 15:51:54 +0200 Subject: [PATCH 07/18] refactor: language migration, use lambda expression to simplify code and remove unused imports Signed-off-by: Carlos Garcia --- .../java/org/quartz/core/QuartzScheduler.java | 14 +- .../quartz/core/jmx/JobDataMapSupport.java | 1 - .../quartz/impl/DirectSchedulerFactory.java | 1 - .../quartz/impl/calendar/AnnualCalendar.java | 1 - .../impl/jdbcjobstore/JobStoreSupport.java | 278 ++++++------------ .../impl/jdbcjobstore/StdJDBCDelegate.java | 1 - .../listeners/BroadcastSchedulerListener.java | 1 - .../xml/XMLSchedulingDataProcessorPlugin.java | 1 - .../simpl/CascadingClassLoadHelper.java | 1 - .../simpl/PropertySettingJobFactory.java | 1 - .../org/quartz/xml/ValidationException.java | 1 - 11 files changed, 89 insertions(+), 212 deletions(-) diff --git a/quartz/src/main/java/org/quartz/core/QuartzScheduler.java b/quartz/src/main/java/org/quartz/core/QuartzScheduler.java index a60fa424a..b2631c615 100644 --- a/quartz/src/main/java/org/quartz/core/QuartzScheduler.java +++ b/quartz/src/main/java/org/quartz/core/QuartzScheduler.java @@ -550,14 +550,12 @@ public void startDelayed(final int seconds) throws SchedulerException "The Scheduler cannot be restarted after shutdown() has been called."); } - Thread t = new Thread(new Runnable() { - public void run() { - try { Thread.sleep(seconds * 1000L); } - catch(InterruptedException ignore) {} - try { start(); } - catch(SchedulerException se) { - getLog().error("Unable to start scheduler after startup delay.", se); - } + Thread t = new Thread(() -> { + try { Thread.sleep(seconds * 1000L); } + catch(InterruptedException ignore) {} + try { start(); } + catch(SchedulerException se) { + getLog().error("Unable to start scheduler after startup delay.", se); } }); t.start(); diff --git a/quartz/src/main/java/org/quartz/core/jmx/JobDataMapSupport.java b/quartz/src/main/java/org/quartz/core/jmx/JobDataMapSupport.java index 5545d09f6..672e4e286 100644 --- a/quartz/src/main/java/org/quartz/core/jmx/JobDataMapSupport.java +++ b/quartz/src/main/java/org/quartz/core/jmx/JobDataMapSupport.java @@ -3,7 +3,6 @@ import static javax.management.openmbean.SimpleType.STRING; import java.util.ArrayList; -import java.util.Iterator; import java.util.Map; import javax.management.openmbean.CompositeData; diff --git a/quartz/src/main/java/org/quartz/impl/DirectSchedulerFactory.java b/quartz/src/main/java/org/quartz/impl/DirectSchedulerFactory.java index b26528d64..00b6795d2 100644 --- a/quartz/src/main/java/org/quartz/impl/DirectSchedulerFactory.java +++ b/quartz/src/main/java/org/quartz/impl/DirectSchedulerFactory.java @@ -19,7 +19,6 @@ package org.quartz.impl; import java.util.Collection; -import java.util.Iterator; import java.util.Map; import java.util.Map.Entry; diff --git a/quartz/src/main/java/org/quartz/impl/calendar/AnnualCalendar.java b/quartz/src/main/java/org/quartz/impl/calendar/AnnualCalendar.java index db1ec60aa..05db1448b 100644 --- a/quartz/src/main/java/org/quartz/impl/calendar/AnnualCalendar.java +++ b/quartz/src/main/java/org/quartz/impl/calendar/AnnualCalendar.java @@ -22,7 +22,6 @@ import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; -import java.util.Iterator; import java.util.TimeZone; import org.quartz.Calendar; diff --git a/quartz/src/main/java/org/quartz/impl/jdbcjobstore/JobStoreSupport.java b/quartz/src/main/java/org/quartz/impl/jdbcjobstore/JobStoreSupport.java index 7b6bae415..b58876e59 100644 --- a/quartz/src/main/java/org/quartz/impl/jdbcjobstore/JobStoreSupport.java +++ b/quartz/src/main/java/org/quartz/impl/jdbcjobstore/JobStoreSupport.java @@ -1246,12 +1246,8 @@ protected boolean triggerExists(Connection conn, TriggerKey key) throws JobPersi public boolean removeJob(final JobKey jobKey) throws JobPersistenceException { return (Boolean) executeInLock( LOCK_TRIGGER_ACCESS, - new TransactionCallback() { - public Object execute(Connection conn) throws JobPersistenceException { - return removeJob(conn, jobKey) ? - Boolean.TRUE : Boolean.FALSE; - } - }); + (TransactionCallback) conn -> removeJob(conn, jobKey) ? + Boolean.TRUE : Boolean.FALSE); } protected boolean removeJob(Connection conn, final JobKey jobKey) @@ -1274,16 +1270,14 @@ public boolean removeJobs(final List jobKeys) throws JobPersistenceExcep return (Boolean) executeInLock( LOCK_TRIGGER_ACCESS, - new TransactionCallback() { - public Object execute(Connection conn) throws JobPersistenceException { - boolean allFound = true; + (TransactionCallback) conn -> { + boolean allFound = true; - // FUTURE_TODO: make this more efficient with a true bulk operation... - for (JobKey jobKey : jobKeys) - allFound = removeJob(conn, jobKey) && allFound; + // FUTURE_TODO: make this more efficient with a true bulk operation... + for (JobKey jobKey : jobKeys) + allFound = removeJob(conn, jobKey) && allFound; - return allFound ? Boolean.TRUE : Boolean.FALSE; - } + return allFound ? Boolean.TRUE : Boolean.FALSE; }); } @@ -1291,16 +1285,14 @@ public boolean removeTriggers(final List triggerKeys) throws JobPersistenceException { return (Boolean) executeInLock( LOCK_TRIGGER_ACCESS, - new TransactionCallback() { - public Object execute(Connection conn) throws JobPersistenceException { - boolean allFound = true; + (TransactionCallback) conn -> { + boolean allFound = true; - // FUTURE_TODO: make this more efficient with a true bulk operation... - for (TriggerKey triggerKey : triggerKeys) - allFound = removeTrigger(conn, triggerKey) && allFound; + // FUTURE_TODO: make this more efficient with a true bulk operation... + for (TriggerKey triggerKey : triggerKeys) + allFound = removeTrigger(conn, triggerKey) && allFound; - return allFound ? Boolean.TRUE : Boolean.FALSE; - } + return allFound ? Boolean.TRUE : Boolean.FALSE; }); } @@ -1360,11 +1352,7 @@ private boolean deleteTriggerAndChildren(Connection conn, TriggerKey key) */ public JobDetail retrieveJob(final JobKey jobKey) throws JobPersistenceException { return (JobDetail)executeWithoutLock( // no locks necessary for read... - new TransactionCallback() { - public Object execute(Connection conn) throws JobPersistenceException { - return retrieveJob(conn, jobKey); - } - }); + (TransactionCallback) conn -> retrieveJob(conn, jobKey)); } protected JobDetail retrieveJob(Connection conn, JobKey key) throws JobPersistenceException { @@ -1410,12 +1398,8 @@ protected JobDetail retrieveJob(Connection conn, JobKey key) throws JobPersisten public boolean removeTrigger(final TriggerKey triggerKey) throws JobPersistenceException { return (Boolean) executeInLock( LOCK_TRIGGER_ACCESS, - new TransactionCallback() { - public Object execute(Connection conn) throws JobPersistenceException { - return removeTrigger(conn, triggerKey) ? - Boolean.TRUE : Boolean.FALSE; - } - }); + (TransactionCallback) conn -> removeTrigger(conn, triggerKey) ? + Boolean.TRUE : Boolean.FALSE); } protected boolean removeTrigger(Connection conn, TriggerKey key) @@ -1453,12 +1437,8 @@ public boolean replaceTrigger(final TriggerKey triggerKey, final OperableTrigger newTrigger) throws JobPersistenceException { return (Boolean) executeInLock( LOCK_TRIGGER_ACCESS, - new TransactionCallback() { - public Object execute(Connection conn) throws JobPersistenceException { - return replaceTrigger(conn, triggerKey, newTrigger) ? - Boolean.TRUE : Boolean.FALSE; - } - }); + (TransactionCallback) conn -> replaceTrigger(conn, triggerKey, newTrigger) ? + Boolean.TRUE : Boolean.FALSE); } protected boolean replaceTrigger(Connection conn, @@ -1499,11 +1479,7 @@ protected boolean replaceTrigger(Connection conn, */ public OperableTrigger retrieveTrigger(final TriggerKey triggerKey) throws JobPersistenceException { return (OperableTrigger)executeWithoutLock( // no locks necessary for read... - new TransactionCallback() { - public Object execute(Connection conn) throws JobPersistenceException { - return retrieveTrigger(conn, triggerKey); - } - }); + (TransactionCallback) conn -> retrieveTrigger(conn, triggerKey)); } protected OperableTrigger retrieveTrigger(Connection conn, TriggerKey key) @@ -1530,11 +1506,7 @@ protected OperableTrigger retrieveTrigger(Connection conn, TriggerKey key) */ public TriggerState getTriggerState(final TriggerKey triggerKey) throws JobPersistenceException { return (TriggerState)executeWithoutLock( // no locks necessary for read... - new TransactionCallback() { - public Object execute(Connection conn) throws JobPersistenceException { - return getTriggerState(conn, triggerKey); - } - }); + (TransactionCallback) conn -> getTriggerState(conn, triggerKey)); } public TriggerState getTriggerState(Connection conn, TriggerKey key) @@ -1714,12 +1686,8 @@ public boolean removeCalendar(final String calName) throws JobPersistenceException { return (Boolean) executeInLock( LOCK_TRIGGER_ACCESS, - new TransactionCallback() { - public Object execute(Connection conn) throws JobPersistenceException { - return removeCalendar(conn, calName) ? - Boolean.TRUE : Boolean.FALSE; - } - }); + (TransactionCallback) conn -> removeCalendar(conn, calName) ? + Boolean.TRUE : Boolean.FALSE); } protected boolean removeCalendar(Connection conn, @@ -1754,11 +1722,7 @@ protected boolean removeCalendar(Connection conn, public Calendar retrieveCalendar(final String calName) throws JobPersistenceException { return (Calendar)executeWithoutLock( // no locks necessary for read... - new TransactionCallback() { - public Object execute(Connection conn) throws JobPersistenceException { - return retrieveCalendar(conn, calName); - } - }); + (TransactionCallback) conn -> retrieveCalendar(conn, calName)); } protected Calendar retrieveCalendar(Connection conn, @@ -1800,11 +1764,7 @@ protected Calendar retrieveCalendar(Connection conn, public int getNumberOfJobs() throws JobPersistenceException { return (Integer) executeWithoutLock( // no locks necessary for read... - new TransactionCallback() { - public Object execute(Connection conn) throws JobPersistenceException { - return getNumberOfJobs(conn); - } - }); + (TransactionCallback) this::getNumberOfJobs); } protected int getNumberOfJobs(Connection conn) @@ -1826,11 +1786,7 @@ protected int getNumberOfJobs(Connection conn) public int getNumberOfTriggers() throws JobPersistenceException { return (Integer) executeWithoutLock( // no locks necessary for read... - new TransactionCallback() { - public Object execute(Connection conn) throws JobPersistenceException { - return getNumberOfTriggers(conn); - } - }); + (TransactionCallback) this::getNumberOfTriggers); } protected int getNumberOfTriggers(Connection conn) @@ -1852,11 +1808,7 @@ protected int getNumberOfTriggers(Connection conn) public int getNumberOfCalendars() throws JobPersistenceException { return (Integer) executeWithoutLock( // no locks necessary for read... - new TransactionCallback() { - public Object execute(Connection conn) throws JobPersistenceException { - return getNumberOfCalendars(conn); - } - }); + (TransactionCallback) this::getNumberOfCalendars); } protected int getNumberOfCalendars(Connection conn) @@ -1883,11 +1835,7 @@ protected int getNumberOfCalendars(Connection conn) public Set getJobKeys(final GroupMatcher matcher) throws JobPersistenceException { return (Set)executeWithoutLock( // no locks necessary for read... - new TransactionCallback() { - public Object execute(Connection conn) throws JobPersistenceException { - return getJobNames(conn, matcher); - } - }); + (TransactionCallback) conn -> getJobNames(conn, matcher)); } protected Set getJobNames(Connection conn, @@ -1915,11 +1863,7 @@ protected Set getJobNames(Connection conn, */ public boolean checkExists(final JobKey jobKey) throws JobPersistenceException { return (Boolean)executeWithoutLock( // no locks necessary for read... - new TransactionCallback() { - public Object execute(Connection conn) throws JobPersistenceException { - return checkExists(conn, jobKey); - } - }); + (TransactionCallback) conn -> checkExists(conn, jobKey)); } protected boolean checkExists(Connection conn, JobKey jobKey) throws JobPersistenceException { @@ -1941,11 +1885,7 @@ protected boolean checkExists(Connection conn, JobKey jobKey) throws JobPersiste */ public boolean checkExists(final TriggerKey triggerKey) throws JobPersistenceException { return (Boolean)executeWithoutLock( // no locks necessary for read... - new TransactionCallback() { - public Object execute(Connection conn) throws JobPersistenceException { - return checkExists(conn, triggerKey); - } - }); + (TransactionCallback) conn -> checkExists(conn, triggerKey)); } protected boolean checkExists(Connection conn, TriggerKey triggerKey) throws JobPersistenceException { @@ -1996,11 +1936,7 @@ protected void clearAllSchedulingData(Connection conn) throws JobPersistenceExce public Set getTriggerKeys(final GroupMatcher matcher) throws JobPersistenceException { return (Set)executeWithoutLock( // no locks necessary for read... - new TransactionCallback() { - public Object execute(Connection conn) throws JobPersistenceException { - return getTriggerNames(conn, matcher); - } - }); + (TransactionCallback) conn -> getTriggerNames(conn, matcher)); } protected Set getTriggerNames(Connection conn, @@ -2034,11 +1970,7 @@ protected Set getTriggerNames(Connection conn, public List getJobGroupNames() throws JobPersistenceException { return (List)executeWithoutLock( // no locks necessary for read... - new TransactionCallback() { - public Object execute(Connection conn) throws JobPersistenceException { - return getJobGroupNames(conn); - } - }); + (TransactionCallback) this::getJobGroupNames); } protected List getJobGroupNames(Connection conn) @@ -2071,11 +2003,7 @@ protected List getJobGroupNames(Connection conn) public List getTriggerGroupNames() throws JobPersistenceException { return (List)executeWithoutLock( // no locks necessary for read... - new TransactionCallback() { - public Object execute(Connection conn) throws JobPersistenceException { - return getTriggerGroupNames(conn); - } - }); + (TransactionCallback) this::getTriggerGroupNames); } protected List getTriggerGroupNames(Connection conn) throws JobPersistenceException { @@ -2107,11 +2035,7 @@ protected List getTriggerGroupNames(Connection conn) throws JobPersisten public List getCalendarNames() throws JobPersistenceException { return (List)executeWithoutLock( // no locks necessary for read... - new TransactionCallback() { - public Object execute(Connection conn) throws JobPersistenceException { - return getCalendarNames(conn); - } - }); + (TransactionCallback) this::getCalendarNames); } protected List getCalendarNames(Connection conn) @@ -2136,11 +2060,7 @@ protected List getCalendarNames(Connection conn) @SuppressWarnings("unchecked") public List getTriggersForJob(final JobKey jobKey) throws JobPersistenceException { return (List)executeWithoutLock( // no locks necessary for read... - new TransactionCallback() { - public Object execute(Connection conn) throws JobPersistenceException { - return getTriggersForJob(conn, jobKey); - } - }); + (TransactionCallback) conn -> getTriggersForJob(conn, jobKey)); } protected List getTriggersForJob(Connection conn, @@ -2240,8 +2160,7 @@ public Set pauseJobs(final GroupMatcher matcher) throws JobPersistenceException { return (Set) executeInLock( LOCK_TRIGGER_ACCESS, - new TransactionCallback() { - public Set execute(final Connection conn) throws JobPersistenceException { + (TransactionCallback) conn -> { Set groupNames = new HashSet<>(); Set jobNames = getJobNames(conn, matcher); @@ -2255,8 +2174,7 @@ public Set execute(final Connection conn) throws JobPersistenceException return groupNames; } - } - ); + ); } /** @@ -2418,8 +2336,7 @@ public Set resumeJobs(final GroupMatcher matcher) throws JobPersistenceException { return (Set) executeInLock( LOCK_TRIGGER_ACCESS, - new TransactionCallback() { - public Set execute(Connection conn) throws JobPersistenceException { + (TransactionCallback) conn -> { Set jobKeys = getJobNames(conn, matcher); Set groupNames = new HashSet<>(); @@ -2431,8 +2348,7 @@ public Set execute(Connection conn) throws JobPersistenceException { groupNames.add(jobKey.getGroup()); } return groupNames; - } - }); + }); } /** @@ -2448,11 +2364,7 @@ public Set pauseTriggers(final GroupMatcher matcher) throws JobPersistenceException { return (Set) executeInLock( LOCK_TRIGGER_ACCESS, - new TransactionCallback() { - public Set execute(Connection conn) throws JobPersistenceException { - return pauseTriggerGroup(conn, matcher); - } - }); + (TransactionCallback) conn -> pauseTriggerGroup(conn, matcher)); } /** @@ -2501,11 +2413,7 @@ public Set pauseTriggerGroup(Connection conn, public Set getPausedTriggerGroups() throws JobPersistenceException { return (Set)executeWithoutLock( // no locks necessary for read... - new TransactionCallback() { - public Object execute(Connection conn) throws JobPersistenceException { - return getPausedTriggerGroups(conn); - } - }); + (TransactionCallback) this::getPausedTriggerGroups); } /** @@ -2545,11 +2453,7 @@ public Set resumeTriggers(final GroupMatcher matcher) throws JobPersistenceException { return (Set) executeInLock( LOCK_TRIGGER_ACCESS, - new TransactionCallback() { - public Set execute(Connection conn) throws JobPersistenceException { - return resumeTriggerGroup(conn, matcher); - } - }); + (TransactionCallback) conn -> resumeTriggerGroup(conn, matcher)); } @@ -2762,28 +2666,22 @@ public List acquireNextTriggers(final long noLaterThan, final i lockName = null; } return executeInNonManagedTXLock(lockName, - new TransactionCallback<>() { - public List execute(Connection conn) throws JobPersistenceException { - return acquireNextTrigger(conn, noLaterThan, maxCount, timeWindow); - } - }, - new TransactionValidator<>() { - public Boolean validate(Connection conn, List result) throws JobPersistenceException { - try { - List acquired = getDelegate().selectInstancesFiredTriggerRecords(conn, getInstanceId()); - Set fireInstanceIds = new HashSet<>(); - for (FiredTriggerRecord ft : acquired) { - fireInstanceIds.add(ft.getFireInstanceId()); - } - for (OperableTrigger tr : result) { - if (fireInstanceIds.contains(tr.getFireInstanceId())) { - return true; - } + conn -> acquireNextTrigger(conn, noLaterThan, maxCount, timeWindow), + (conn, result) -> { + try { + List acquired = getDelegate().selectInstancesFiredTriggerRecords(conn, getInstanceId()); + Set fireInstanceIds = new HashSet<>(); + for (FiredTriggerRecord ft : acquired) { + fireInstanceIds.add(ft.getFireInstanceId()); + } + for (OperableTrigger tr : result) { + if (fireInstanceIds.contains(tr.getFireInstanceId())) { + return true; } - return false; - } catch (SQLException e) { - throw new JobPersistenceException("error validating trigger acquisition", e); } + return false; + } catch (SQLException e) { + throw new JobPersistenceException("error validating trigger acquisition", e); } }); } @@ -2937,44 +2835,39 @@ protected void releaseAcquiredTrigger(Connection conn, @SuppressWarnings("unchecked") public List triggersFired(final List triggers) throws JobPersistenceException { return executeInNonManagedTXLock(LOCK_TRIGGER_ACCESS, - new TransactionCallback<>() { - public List execute(Connection conn) throws JobPersistenceException { - List results = new ArrayList<>(); + conn -> { + List results = new ArrayList<>(); - TriggerFiredResult result; - for (OperableTrigger trigger : triggers) { - try { - TriggerFiredBundle bundle = triggerFired(conn, trigger); - result = new TriggerFiredResult(bundle); - } catch (JobPersistenceException | RuntimeException jpe) { - result = new TriggerFiredResult(jpe); - } - results.add(result); + TriggerFiredResult result; + for (OperableTrigger trigger : triggers) { + try { + TriggerFiredBundle bundle = triggerFired(conn, trigger); + result = new TriggerFiredResult(bundle); + } catch (JobPersistenceException | RuntimeException jpe) { + result = new TriggerFiredResult(jpe); } - - return results; + results.add(result); } + + return results; }, - new TransactionValidator<>() { - @Override - public Boolean validate(Connection conn, List result) throws JobPersistenceException { - try { - List acquired = getDelegate().selectInstancesFiredTriggerRecords(conn, getInstanceId()); - Set executingTriggers = new HashSet<>(); - for (FiredTriggerRecord ft : acquired) { - if (STATE_EXECUTING.equals(ft.getFireInstanceState())) { - executingTriggers.add(ft.getFireInstanceId()); - } + (conn, result) -> { + try { + List acquired = getDelegate().selectInstancesFiredTriggerRecords(conn, getInstanceId()); + Set executingTriggers = new HashSet<>(); + for (FiredTriggerRecord ft : acquired) { + if (STATE_EXECUTING.equals(ft.getFireInstanceState())) { + executingTriggers.add(ft.getFireInstanceId()); } - for (TriggerFiredResult tr : result) { - if (tr.getTriggerFiredBundle() != null && executingTriggers.contains(tr.getTriggerFiredBundle().getTrigger().getFireInstanceId())) { - return true; - } + } + for (TriggerFiredResult tr : result) { + if (tr.getTriggerFiredBundle() != null && executingTriggers.contains(tr.getTriggerFiredBundle().getTrigger().getFireInstanceId())) { + return true; } - return false; - } catch (SQLException e) { - throw new JobPersistenceException("error validating trigger acquisition", e); } + return false; + } catch (SQLException e) { + throw new JobPersistenceException("error validating trigger acquisition", e); } }); } @@ -3811,12 +3704,7 @@ protected T executeInNonManagedTXLock( commitConnection(conn); } catch (JobPersistenceException e) { rollbackConnection(conn); - if (txValidator == null || !retryExecuteInNonManagedTXLock(lockName, new TransactionCallback() { - @Override - public Boolean execute(Connection conn) throws JobPersistenceException { - return txValidator.validate(conn, result); - } - })) { + if (txValidator == null || !retryExecuteInNonManagedTXLock(lockName, conn1 -> txValidator.validate(conn1, result))) { throw e; } } diff --git a/quartz/src/main/java/org/quartz/impl/jdbcjobstore/StdJDBCDelegate.java b/quartz/src/main/java/org/quartz/impl/jdbcjobstore/StdJDBCDelegate.java index abac42981..5ef222ed1 100644 --- a/quartz/src/main/java/org/quartz/impl/jdbcjobstore/StdJDBCDelegate.java +++ b/quartz/src/main/java/org/quartz/impl/jdbcjobstore/StdJDBCDelegate.java @@ -39,7 +39,6 @@ import java.util.Date; import java.util.HashMap; import java.util.HashSet; -import java.util.Iterator; import java.util.LinkedList; import java.util.List; import java.util.Map; diff --git a/quartz/src/main/java/org/quartz/listeners/BroadcastSchedulerListener.java b/quartz/src/main/java/org/quartz/listeners/BroadcastSchedulerListener.java index a29e2b2c4..44d7c9cf8 100644 --- a/quartz/src/main/java/org/quartz/listeners/BroadcastSchedulerListener.java +++ b/quartz/src/main/java/org/quartz/listeners/BroadcastSchedulerListener.java @@ -1,6 +1,5 @@ package org.quartz.listeners; -import java.util.Iterator; import java.util.LinkedList; import java.util.List; diff --git a/quartz/src/main/java/org/quartz/plugins/xml/XMLSchedulingDataProcessorPlugin.java b/quartz/src/main/java/org/quartz/plugins/xml/XMLSchedulingDataProcessorPlugin.java index a41f53658..c37314e93 100644 --- a/quartz/src/main/java/org/quartz/plugins/xml/XMLSchedulingDataProcessorPlugin.java +++ b/quartz/src/main/java/org/quartz/plugins/xml/XMLSchedulingDataProcessorPlugin.java @@ -26,7 +26,6 @@ import java.net.URLDecoder; import java.nio.charset.StandardCharsets; import java.util.HashSet; -import java.util.Iterator; import java.util.LinkedHashMap; import java.util.Map; import java.util.Set; diff --git a/quartz/src/main/java/org/quartz/simpl/CascadingClassLoadHelper.java b/quartz/src/main/java/org/quartz/simpl/CascadingClassLoadHelper.java index 0403915bf..fbbfeca45 100644 --- a/quartz/src/main/java/org/quartz/simpl/CascadingClassLoadHelper.java +++ b/quartz/src/main/java/org/quartz/simpl/CascadingClassLoadHelper.java @@ -18,7 +18,6 @@ package org.quartz.simpl; -import java.util.Iterator; import java.util.LinkedList; import java.net.URL; import java.io.InputStream; diff --git a/quartz/src/main/java/org/quartz/simpl/PropertySettingJobFactory.java b/quartz/src/main/java/org/quartz/simpl/PropertySettingJobFactory.java index 03aa8e8ad..75e92aa76 100644 --- a/quartz/src/main/java/org/quartz/simpl/PropertySettingJobFactory.java +++ b/quartz/src/main/java/org/quartz/simpl/PropertySettingJobFactory.java @@ -22,7 +22,6 @@ import java.beans.Introspector; import java.beans.PropertyDescriptor; import java.lang.reflect.InvocationTargetException; -import java.util.Iterator; import java.util.Locale; import java.util.Map; diff --git a/quartz/src/main/java/org/quartz/xml/ValidationException.java b/quartz/src/main/java/org/quartz/xml/ValidationException.java index b1a3d4943..63264f4b5 100644 --- a/quartz/src/main/java/org/quartz/xml/ValidationException.java +++ b/quartz/src/main/java/org/quartz/xml/ValidationException.java @@ -21,7 +21,6 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Collections; -import java.util.Iterator; /** * Reports JobSchedulingDataLoader validation exceptions. From b8ffa6423fa456b7fb73bd11001da06dbe7535aa Mon Sep 17 00:00:00 2001 From: Carlos Garcia Date: Wed, 16 Oct 2024 15:55:15 +0200 Subject: [PATCH 08/18] refactor: remove redundant variable declaration Signed-off-by: Carlos Garcia --- .../java/org/quartz/core/QuartzScheduler.java | 18 +++++-------- .../java/org/quartz/impl/JobDetailImpl.java | 3 +-- .../java/org/quartz/impl/RemoteScheduler.java | 6 ++--- .../org/quartz/impl/StdSchedulerFactory.java | 3 +-- .../quartz/impl/calendar/CronCalendar.java | 5 ++-- .../quartz/impl/calendar/DailyCalendar.java | 3 +-- .../impl/jdbcjobstore/HSQLDBDelegate.java | 3 +-- .../impl/jdbcjobstore/MSSQLDelegate.java | 3 +-- .../impl/jdbcjobstore/PointbaseDelegate.java | 3 +-- .../impl/jdbcjobstore/StdJDBCDelegate.java | 25 +++++++------------ .../impl/jdbcjobstore/SybaseDelegate.java | 3 +-- .../jdbcjobstore/oracle/OracleDelegate.java | 3 +-- .../simpl/PropertySettingJobFactory.java | 5 ++-- .../java/org/quartz/simpl/RAMJobStore.java | 5 ++-- .../org/quartz/simpl/SimpleJobFactory.java | 3 +-- 15 files changed, 32 insertions(+), 59 deletions(-) diff --git a/quartz/src/main/java/org/quartz/core/QuartzScheduler.java b/quartz/src/main/java/org/quartz/core/QuartzScheduler.java index b2631c615..7ee9f06d3 100644 --- a/quartz/src/main/java/org/quartz/core/QuartzScheduler.java +++ b/quartz/src/main/java/org/quartz/core/QuartzScheduler.java @@ -1849,10 +1849,9 @@ public boolean notifyTriggerListenersFired(JobExecutionContext jec) vetoedExecution = true; } } catch (Exception e) { - SchedulerException se = new SchedulerException( + throw new SchedulerException( "TriggerListener '" + tl.getName() + "' threw exception: " + e.getMessage(), e); - throw se; } } @@ -1872,10 +1871,9 @@ public void notifyTriggerListenersMisfired(Trigger trigger) continue; tl.triggerMisfired(trigger); } catch (Exception e) { - SchedulerException se = new SchedulerException( + throw new SchedulerException( "TriggerListener '" + tl.getName() + "' threw exception: " + e.getMessage(), e); - throw se; } } } @@ -1892,10 +1890,9 @@ public void notifyTriggerListenersComplete(JobExecutionContext jec, continue; tl.triggerComplete(jec.getTrigger(), jec, instCode); } catch (Exception e) { - SchedulerException se = new SchedulerException( + throw new SchedulerException( "TriggerListener '" + tl.getName() + "' threw exception: " + e.getMessage(), e); - throw se; } } } @@ -1912,10 +1909,9 @@ public void notifyJobListenersToBeExecuted(JobExecutionContext jec) continue; jl.jobToBeExecuted(jec); } catch (Exception e) { - SchedulerException se = new SchedulerException( + throw new SchedulerException( "JobListener '" + jl.getName() + "' threw exception: " + e.getMessage(), e); - throw se; } } } @@ -1932,10 +1928,9 @@ public void notifyJobListenersWasVetoed(JobExecutionContext jec) continue; jl.jobExecutionVetoed(jec); } catch (Exception e) { - SchedulerException se = new SchedulerException( + throw new SchedulerException( "JobListener '" + jl.getName() + "' threw exception: " + e.getMessage(), e); - throw se; } } } @@ -1952,10 +1947,9 @@ public void notifyJobListenersWasExecuted(JobExecutionContext jec, continue; jl.jobWasExecuted(jec, je); } catch (Exception e) { - SchedulerException se = new SchedulerException( + throw new SchedulerException( "JobListener '" + jl.getName() + "' threw exception: " + e.getMessage(), e); - throw se; } } } diff --git a/quartz/src/main/java/org/quartz/impl/JobDetailImpl.java b/quartz/src/main/java/org/quartz/impl/JobDetailImpl.java index 8dfb31a8c..b270e3aac 100644 --- a/quartz/src/main/java/org/quartz/impl/JobDetailImpl.java +++ b/quartz/src/main/java/org/quartz/impl/JobDetailImpl.java @@ -449,13 +449,12 @@ public Object clone() { } public JobBuilder getJobBuilder() { - JobBuilder b = JobBuilder.newJob() + return JobBuilder.newJob() .ofType(getJobClass()) .requestRecovery(requestsRecovery()) .storeDurably(isDurable()) .usingJobData(getJobDataMap()) .withDescription(getDescription()) .withIdentity(getKey()); - return b; } } diff --git a/quartz/src/main/java/org/quartz/impl/RemoteScheduler.java b/quartz/src/main/java/org/quartz/impl/RemoteScheduler.java index f7e2631d0..9d8ac3dd5 100644 --- a/quartz/src/main/java/org/quartz/impl/RemoteScheduler.java +++ b/quartz/src/main/java/org/quartz/impl/RemoteScheduler.java @@ -115,10 +115,9 @@ protected RemotableQuartzScheduler getRemoteScheduler() rsched = (RemotableQuartzScheduler) registry.lookup(schedId); } catch (Exception e) { - SchedulerException initException = new SchedulerException( + throw new SchedulerException( "Could not get handle to remote scheduler: " + e.getMessage(), e); - throw initException; } return rsched; @@ -127,8 +126,7 @@ protected RemotableQuartzScheduler getRemoteScheduler() protected SchedulerException invalidateHandleCreateException(String msg, Exception cause) { rsched = null; - SchedulerException ex = new SchedulerException(msg, cause); - return ex; + return new SchedulerException(msg, cause); } /** diff --git a/quartz/src/main/java/org/quartz/impl/StdSchedulerFactory.java b/quartz/src/main/java/org/quartz/impl/StdSchedulerFactory.java index 650c463fb..ee87bdf04 100644 --- a/quartz/src/main/java/org/quartz/impl/StdSchedulerFactory.java +++ b/quartz/src/main/java/org/quartz/impl/StdSchedulerFactory.java @@ -1428,8 +1428,7 @@ else if(tpInited) protected Scheduler instantiate(QuartzSchedulerResources rsrcs, QuartzScheduler qs) { - Scheduler scheduler = new StdScheduler(qs); - return scheduler; + return new StdScheduler(qs); } diff --git a/quartz/src/main/java/org/quartz/impl/calendar/CronCalendar.java b/quartz/src/main/java/org/quartz/impl/calendar/CronCalendar.java index 5160968a0..b5b785ca3 100644 --- a/quartz/src/main/java/org/quartz/impl/calendar/CronCalendar.java +++ b/quartz/src/main/java/org/quartz/impl/calendar/CronCalendar.java @@ -204,9 +204,8 @@ public CronExpression getCronExpression() { * if the string expression cannot be parsed */ public void setCronExpression(String expression) throws ParseException { - CronExpression newExp = new CronExpression(expression); - - this.cronExpression = newExp; + + this.cronExpression = new CronExpression(expression); } /** diff --git a/quartz/src/main/java/org/quartz/impl/calendar/DailyCalendar.java b/quartz/src/main/java/org/quartz/impl/calendar/DailyCalendar.java index 669d6c106..e975d93d2 100644 --- a/quartz/src/main/java/org/quartz/impl/calendar/DailyCalendar.java +++ b/quartz/src/main/java/org/quartz/impl/calendar/DailyCalendar.java @@ -450,8 +450,7 @@ public DailyCalendar(org.quartz.Calendar baseCalendar, @Override public Object clone() { - DailyCalendar clone = (DailyCalendar) super.clone(); - return clone; + return (DailyCalendar) super.clone(); } /** diff --git a/quartz/src/main/java/org/quartz/impl/jdbcjobstore/HSQLDBDelegate.java b/quartz/src/main/java/org/quartz/impl/jdbcjobstore/HSQLDBDelegate.java index f064e4a3a..ebade390d 100644 --- a/quartz/src/main/java/org/quartz/impl/jdbcjobstore/HSQLDBDelegate.java +++ b/quartz/src/main/java/org/quartz/impl/jdbcjobstore/HSQLDBDelegate.java @@ -78,8 +78,7 @@ protected Object getObjectFromBlob(ResultSet rs, String colName) protected Object getJobDataFromBlob(ResultSet rs, String colName) throws ClassNotFoundException, IOException, SQLException { if (canUseProperties()) { - InputStream binaryInput = rs.getBinaryStream(colName); - return binaryInput; + return rs.getBinaryStream(colName); } return getObjectFromBlob(rs, colName); } diff --git a/quartz/src/main/java/org/quartz/impl/jdbcjobstore/MSSQLDelegate.java b/quartz/src/main/java/org/quartz/impl/jdbcjobstore/MSSQLDelegate.java index 165f167f3..bbbbbf9ec 100644 --- a/quartz/src/main/java/org/quartz/impl/jdbcjobstore/MSSQLDelegate.java +++ b/quartz/src/main/java/org/quartz/impl/jdbcjobstore/MSSQLDelegate.java @@ -76,8 +76,7 @@ protected Object getObjectFromBlob(ResultSet rs, String colName) protected Object getJobDataFromBlob(ResultSet rs, String colName) throws ClassNotFoundException, IOException, SQLException { if (canUseProperties()) { - InputStream binaryInput = rs.getBinaryStream(colName); - return binaryInput; + return rs.getBinaryStream(colName); } return getObjectFromBlob(rs, colName); } diff --git a/quartz/src/main/java/org/quartz/impl/jdbcjobstore/PointbaseDelegate.java b/quartz/src/main/java/org/quartz/impl/jdbcjobstore/PointbaseDelegate.java index 0677e65dc..179dc7d9c 100644 --- a/quartz/src/main/java/org/quartz/impl/jdbcjobstore/PointbaseDelegate.java +++ b/quartz/src/main/java/org/quartz/impl/jdbcjobstore/PointbaseDelegate.java @@ -444,8 +444,7 @@ protected Object getJobDataFromBlob(ResultSet rs, String colName) if(data == null) { return null; } - InputStream binaryInput = new ByteArrayInputStream(data); - return binaryInput; + return new ByteArrayInputStream(data); } return getObjectFromBlob(rs, colName); diff --git a/quartz/src/main/java/org/quartz/impl/jdbcjobstore/StdJDBCDelegate.java b/quartz/src/main/java/org/quartz/impl/jdbcjobstore/StdJDBCDelegate.java index 5ef222ed1..c5018dae2 100644 --- a/quartz/src/main/java/org/quartz/impl/jdbcjobstore/StdJDBCDelegate.java +++ b/quartz/src/main/java/org/quartz/impl/jdbcjobstore/StdJDBCDelegate.java @@ -2120,9 +2120,8 @@ public int insertPausedTriggerGroup(Connection conn, String groupName) try { ps = conn.prepareStatement(rtp(INSERT_PAUSED_TRIGGER_GROUP)); ps.setString(1, groupName); - int rows = ps.executeUpdate(); - return rows; + return ps.executeUpdate(); } finally { closeStatement(ps); } @@ -2135,9 +2134,8 @@ public int deletePausedTriggerGroup(Connection conn, String groupName) try { ps = conn.prepareStatement(rtp(DELETE_PAUSED_TRIGGER_GROUP)); ps.setString(1, groupName); - int rows = ps.executeUpdate(); - return rows; + return ps.executeUpdate(); } finally { closeStatement(ps); } @@ -2150,9 +2148,8 @@ public int deletePausedTriggerGroup(Connection conn, GroupMatcher ma try { ps = conn.prepareStatement(rtp(DELETE_PAUSED_TRIGGER_GROUP)); ps.setString(1, toSqlLikeClause(matcher)); - int rows = ps.executeUpdate(); - return rows; + return ps.executeUpdate(); } finally { closeStatement(ps); } @@ -2164,9 +2161,8 @@ public int deleteAllPausedTriggerGroups(Connection conn) try { ps = conn.prepareStatement(rtp(DELETE_PAUSED_TRIGGER_GROUPS)); - int rows = ps.executeUpdate(); - return rows; + return ps.executeUpdate(); } finally { closeStatement(ps); } @@ -3076,11 +3072,10 @@ protected ByteArrayOutputStream serializeJobData(JobDataMap data) */ protected Object getKeyOfNonSerializableValue(Map data) { for (Map.Entry value : data.entrySet()) { - Map.Entry entry = (Map.Entry) value; - try (ByteArrayOutputStream baos = serializeObject(entry.getValue())) { + try (ByteArrayOutputStream baos = serializeObject(((Map.Entry) value).getValue())) { } catch (IOException e) { - return entry.getKey(); + return ((Map.Entry) value).getKey(); } } @@ -3117,10 +3112,9 @@ protected Properties convertToProperty(Map data) throws IOException { Properties properties = new Properties(); for (Map.Entry value : data.entrySet()) { - Map.Entry entry = (Map.Entry) value; - Object key = entry.getKey(); - Object val = (entry.getValue() == null) ? "" : entry.getValue(); + Object key = ((Map.Entry) value).getKey(); + Object val = (((Map.Entry) value).getValue() == null) ? "" : ((Map.Entry) value).getValue(); if (!(key instanceof String)) { throw new IOException("JobDataMap keys/values must be Strings " @@ -3202,8 +3196,7 @@ protected Object getJobDataFromBlob(ResultSet rs, String colName) if (canUseProperties()) { Blob blobLocator = rs.getBlob(colName); if (blobLocator != null) { - InputStream binaryInput = blobLocator.getBinaryStream(); - return binaryInput; + return blobLocator.getBinaryStream(); } else { return null; } diff --git a/quartz/src/main/java/org/quartz/impl/jdbcjobstore/SybaseDelegate.java b/quartz/src/main/java/org/quartz/impl/jdbcjobstore/SybaseDelegate.java index 795372805..f325cfba9 100644 --- a/quartz/src/main/java/org/quartz/impl/jdbcjobstore/SybaseDelegate.java +++ b/quartz/src/main/java/org/quartz/impl/jdbcjobstore/SybaseDelegate.java @@ -80,8 +80,7 @@ protected Object getObjectFromBlob(ResultSet rs, String colName) protected Object getJobDataFromBlob(ResultSet rs, String colName) throws ClassNotFoundException, IOException, SQLException { if (canUseProperties()) { - InputStream binaryInput = rs.getBinaryStream(colName); - return binaryInput; + return rs.getBinaryStream(colName); } return getObjectFromBlob(rs, colName); } diff --git a/quartz/src/main/java/org/quartz/impl/jdbcjobstore/oracle/OracleDelegate.java b/quartz/src/main/java/org/quartz/impl/jdbcjobstore/oracle/OracleDelegate.java index f379aef65..7b6a01397 100644 --- a/quartz/src/main/java/org/quartz/impl/jdbcjobstore/oracle/OracleDelegate.java +++ b/quartz/src/main/java/org/quartz/impl/jdbcjobstore/oracle/OracleDelegate.java @@ -204,8 +204,7 @@ protected Object getJobDataFromBlob(ResultSet rs, String colName) throws ClassNotFoundException, IOException, SQLException { if (canUseProperties()) { - InputStream binaryInput = rs.getBinaryStream(colName); - return binaryInput; + return rs.getBinaryStream(colName); } return getObjectFromBlob(rs, colName); diff --git a/quartz/src/main/java/org/quartz/simpl/PropertySettingJobFactory.java b/quartz/src/main/java/org/quartz/simpl/PropertySettingJobFactory.java index 75e92aa76..ded965326 100644 --- a/quartz/src/main/java/org/quartz/simpl/PropertySettingJobFactory.java +++ b/quartz/src/main/java/org/quartz/simpl/PropertySettingJobFactory.java @@ -92,9 +92,8 @@ protected void setBeanProps(Object obj, JobDataMap data) throws SchedulerExcepti // Get the wrapped entry set so don't have to incur overhead of wrapping for // dirty flag checking since this is read only access for (Map.Entry stringObjectEntry : data.getWrappedMap().entrySet()) { - Map.Entry entry = (Map.Entry) stringObjectEntry; - String name = (String) entry.getKey(); + String name = (String) ((Map.Entry) stringObjectEntry).getKey(); String c = name.substring(0, 1).toUpperCase(Locale.US); String methName = "set" + c + name.substring(1); @@ -112,7 +111,7 @@ protected void setBeanProps(Object obj, JobDataMap data) throws SchedulerExcepti } paramType = setMeth.getParameterTypes()[0]; - o = entry.getValue(); + o = ((Map.Entry) stringObjectEntry).getValue(); Object parm = null; if (paramType.isPrimitive()) { diff --git a/quartz/src/main/java/org/quartz/simpl/RAMJobStore.java b/quartz/src/main/java/org/quartz/simpl/RAMJobStore.java index 1844da626..6668bce14 100644 --- a/quartz/src/main/java/org/quartz/simpl/RAMJobStore.java +++ b/quartz/src/main/java/org/quartz/simpl/RAMJobStore.java @@ -1707,9 +1707,8 @@ protected String peekTriggers() { * @see org.quartz.spi.JobStore#getPausedTriggerGroups() */ public Set getPausedTriggerGroups() throws JobPersistenceException { - HashSet set = new HashSet<>(pausedTriggerGroups); - - return set; + + return new HashSet<>(pausedTriggerGroups); } public void setInstanceId(String schedInstId) { diff --git a/quartz/src/main/java/org/quartz/simpl/SimpleJobFactory.java b/quartz/src/main/java/org/quartz/simpl/SimpleJobFactory.java index 803e871a6..faee3f866 100644 --- a/quartz/src/main/java/org/quartz/simpl/SimpleJobFactory.java +++ b/quartz/src/main/java/org/quartz/simpl/SimpleJobFactory.java @@ -54,10 +54,9 @@ public Job newJob(TriggerFiredBundle bundle, Scheduler Scheduler) throws Schedul return jobClass.newInstance(); } catch (Exception e) { - SchedulerException se = new SchedulerException( + throw new SchedulerException( "Problem instantiating class '" + jobDetail.getJobClass().getName() + "'", e); - throw se; } } From 835d82e4d16941bc48cf63d6723785aa3f6851a3 Mon Sep 17 00:00:00 2001 From: Carlos Garcia Date: Wed, 16 Oct 2024 16:24:47 +0200 Subject: [PATCH 09/18] refactor: simplify boolean expression Signed-off-by: Carlos Garcia --- .../java/org/quartz/core/jmx/TriggerSupport.java | 4 +--- .../quartz/impl/jdbcjobstore/PointbaseDelegate.java | 2 +- .../quartz/impl/jdbcjobstore/StdJDBCDelegate.java | 10 ++++------ .../impl/triggers/DailyTimeIntervalTriggerImpl.java | 2 -- .../org/quartz/impl/triggers/SimpleTriggerImpl.java | 2 +- .../src/main/java/org/quartz/simpl/RAMJobStore.java | 8 ++++---- quartz/src/main/java/org/quartz/utils/Key.java | 13 ++++--------- .../java/org/quartz/xml/ValidationException.java | 4 ---- 8 files changed, 15 insertions(+), 30 deletions(-) diff --git a/quartz/src/main/java/org/quartz/core/jmx/TriggerSupport.java b/quartz/src/main/java/org/quartz/core/jmx/TriggerSupport.java index 8800cf2dd..23cff5522 100644 --- a/quartz/src/main/java/org/quartz/core/jmx/TriggerSupport.java +++ b/quartz/src/main/java/org/quartz/core/jmx/TriggerSupport.java @@ -113,9 +113,7 @@ public static List toCompositeList(List trigge List result = new ArrayList<>(); for(Trigger trigger : triggers) { CompositeData cData = TriggerSupport.toCompositeData(trigger); - if(cData != null) { - result.add(cData); - } + result.add(cData); } return result; } diff --git a/quartz/src/main/java/org/quartz/impl/jdbcjobstore/PointbaseDelegate.java b/quartz/src/main/java/org/quartz/impl/jdbcjobstore/PointbaseDelegate.java index 179dc7d9c..40feb4289 100644 --- a/quartz/src/main/java/org/quartz/impl/jdbcjobstore/PointbaseDelegate.java +++ b/quartz/src/main/java/org/quartz/impl/jdbcjobstore/PointbaseDelegate.java @@ -409,7 +409,7 @@ protected Object getObjectFromBlob(ResultSet rs, String colName) InputStream binaryInput = new ByteArrayInputStream(binaryData); - if (null != binaryInput && binaryInput.available() != 0) { + if (binaryInput.available() != 0) { try (ObjectInputStream in = new ObjectInputStream(binaryInput)) { obj = in.readObject(); } diff --git a/quartz/src/main/java/org/quartz/impl/jdbcjobstore/StdJDBCDelegate.java b/quartz/src/main/java/org/quartz/impl/jdbcjobstore/StdJDBCDelegate.java index c5018dae2..9be39157f 100644 --- a/quartz/src/main/java/org/quartz/impl/jdbcjobstore/StdJDBCDelegate.java +++ b/quartz/src/main/java/org/quartz/impl/jdbcjobstore/StdJDBCDelegate.java @@ -879,12 +879,10 @@ public JobDetail selectJobDetail(Connection conn, JobKey jobKey, return null; } Properties properties = new Properties(); - if (is != null) { - try { - properties.load(is); - } finally { - is.close(); - } + try { + properties.load(is); + } finally { + is.close(); } map = convertFromProperty(properties); return map; diff --git a/quartz/src/main/java/org/quartz/impl/triggers/DailyTimeIntervalTriggerImpl.java b/quartz/src/main/java/org/quartz/impl/triggers/DailyTimeIntervalTriggerImpl.java index 479624733..042e69c38 100644 --- a/quartz/src/main/java/org/quartz/impl/triggers/DailyTimeIntervalTriggerImpl.java +++ b/quartz/src/main/java/org/quartz/impl/triggers/DailyTimeIntervalTriggerImpl.java @@ -875,8 +875,6 @@ public Set getDaysOfWeek() { public void setDaysOfWeek(Set daysOfWeek) { if(daysOfWeek == null || daysOfWeek.isEmpty()) throw new IllegalArgumentException("DaysOfWeek set must be a set that contains at least one day."); - else if(daysOfWeek.isEmpty()) - throw new IllegalArgumentException("DaysOfWeek set must contain at least one day."); this.daysOfWeek = daysOfWeek; } diff --git a/quartz/src/main/java/org/quartz/impl/triggers/SimpleTriggerImpl.java b/quartz/src/main/java/org/quartz/impl/triggers/SimpleTriggerImpl.java index 23f040e47..b03c93494 100644 --- a/quartz/src/main/java/org/quartz/impl/triggers/SimpleTriggerImpl.java +++ b/quartz/src/main/java/org/quartz/impl/triggers/SimpleTriggerImpl.java @@ -313,7 +313,7 @@ public void setStartTime(Date startTime) { } Date eTime = getEndTime(); - if (eTime != null && startTime != null && eTime.before(startTime)) { + if (eTime != null && eTime.before(startTime)) { throw new IllegalArgumentException( "End time cannot be before start time"); } diff --git a/quartz/src/main/java/org/quartz/simpl/RAMJobStore.java b/quartz/src/main/java/org/quartz/simpl/RAMJobStore.java index 6668bce14..b68954304 100644 --- a/quartz/src/main/java/org/quartz/simpl/RAMJobStore.java +++ b/quartz/src/main/java/org/quartz/simpl/RAMJobStore.java @@ -672,7 +672,7 @@ public void resetTriggerFromErrorState(final TriggerKey triggerKey) throws JobPe TriggerWrapper tw = triggersByKey.get(triggerKey); // does the trigger exist? - if (tw == null || tw.trigger == null) { + if (tw == null) { return; } // is the trigger in error state? @@ -1043,7 +1043,7 @@ public void pauseTrigger(TriggerKey triggerKey) { TriggerWrapper tw = triggersByKey.get(triggerKey); // does the trigger exist? - if (tw == null || tw.trigger == null) { + if (tw == null) { return; } @@ -1190,7 +1190,7 @@ public void resumeTrigger(TriggerKey triggerKey) { TriggerWrapper tw = triggersByKey.get(triggerKey); // does the trigger exist? - if (tw == null || tw.trigger == null) { + if (tw == null) { return; } @@ -1527,7 +1527,7 @@ public List triggersFired(List firedTrigger for (OperableTrigger trigger : firedTriggers) { TriggerWrapper tw = triggersByKey.get(trigger.getKey()); // was the trigger deleted since being acquired? - if (tw == null || tw.trigger == null) { + if (tw == null) { continue; } // was the trigger completed, paused, blocked, etc. since being acquired? diff --git a/quartz/src/main/java/org/quartz/utils/Key.java b/quartz/src/main/java/org/quartz/utils/Key.java index 82c3b26a0..82d3b2fbc 100644 --- a/quartz/src/main/java/org/quartz/utils/Key.java +++ b/quartz/src/main/java/org/quartz/utils/Key.java @@ -115,8 +115,8 @@ public String toString() { public int hashCode() { final int prime = 31; int result = 1; - result = prime * result + ((group == null) ? 0 : group.hashCode()); - result = prime * result + ((name == null) ? 0 : name.hashCode()); + result = prime * result + group.hashCode(); + result = prime * result + name.hashCode(); return result; } @@ -130,14 +130,9 @@ public boolean equals(Object obj) { return false; @SuppressWarnings("unchecked") Key other = (Key) obj; - if (group == null) { - if (other.group != null) - return false; - } else if (!group.equals(other.group)) + if (!group.equals(other.group)) return false; - if (name == null) { - return other.name == null; - } else return name.equals(other.name); + return name.equals(other.name); } public int compareTo(Key o) { diff --git a/quartz/src/main/java/org/quartz/xml/ValidationException.java b/quartz/src/main/java/org/quartz/xml/ValidationException.java index 63264f4b5..1c3fbf6ac 100644 --- a/quartz/src/main/java/org/quartz/xml/ValidationException.java +++ b/quartz/src/main/java/org/quartz/xml/ValidationException.java @@ -126,10 +126,6 @@ public String getMessage() { boolean first = true; for (Exception e : getValidationExceptions()) { - if (!first) { - sb.append('\n'); - first = false; - } sb.append(e.getMessage()); } From 43024163e0f88eac37d63d9061008838d9b42f8c Mon Sep 17 00:00:00 2001 From: Carlos Garcia Date: Wed, 16 Oct 2024 16:33:40 +0200 Subject: [PATCH 10/18] rollback change made by mistake in gradle configuration file Signed-off-by: Carlos Garcia --- quartz-jobs/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/quartz-jobs/build.gradle b/quartz-jobs/build.gradle index 73c3d8d39..2fce21b09 100644 --- a/quartz-jobs/build.gradle +++ b/quartz-jobs/build.gradle @@ -29,7 +29,7 @@ java { } test { - maxParallelForks 10 + maxParallelForks 1 forkEvery 1 } From 33c0a9a3382f3ef538688ff602039f57e7abe6eb Mon Sep 17 00:00:00 2001 From: Carlos Garcia Date: Wed, 16 Oct 2024 18:40:44 +0200 Subject: [PATCH 11/18] optimize code and use java naming convention for constants Signed-off-by: Carlos Garcia --- .../org/quartz/core/jmx/JobDataMapSupport.java | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/quartz/src/main/java/org/quartz/core/jmx/JobDataMapSupport.java b/quartz/src/main/java/org/quartz/core/jmx/JobDataMapSupport.java index 672e4e286..27950affd 100644 --- a/quartz/src/main/java/org/quartz/core/jmx/JobDataMapSupport.java +++ b/quartz/src/main/java/org/quartz/core/jmx/JobDataMapSupport.java @@ -17,7 +17,7 @@ import org.quartz.JobDataMap; public class JobDataMapSupport { - private static final String typeName = "JobDataMap"; + private static final String TYPE_NAME = "JobDataMap"; private static final String[] keyValue = new String[] { "key", "value" }; private static final OpenType[] openTypes = new OpenType[] { STRING, STRING }; private static final CompositeType rowType; @@ -25,9 +25,9 @@ public class JobDataMapSupport { static { try { - rowType = new CompositeType(typeName, typeName, keyValue, keyValue, + rowType = new CompositeType(TYPE_NAME, TYPE_NAME, keyValue, keyValue, openTypes); - TABULAR_TYPE = new TabularType(typeName, typeName, rowType, + TABULAR_TYPE = new TabularType(TYPE_NAME, TYPE_NAME, rowType, new String[] { "key" }); } catch (OpenDataException e) { throw new RuntimeException(e); @@ -50,12 +50,10 @@ public static JobDataMap newJobDataMap(TabularData tabularData) { public static JobDataMap newJobDataMap(Map map) { JobDataMap jobDataMap = new JobDataMap(); - if(map != null) { - for (String key : map.keySet()) { - jobDataMap.put(key, map.get(key)); - } + if (map != null) { + jobDataMap.putAll(map); } - + return jobDataMap; } @@ -78,8 +76,8 @@ public static CompositeData toCompositeData(String key, String value) { public static TabularData toTabularData(JobDataMap jobDataMap) { TabularData tData = new TabularDataSupport(TABULAR_TYPE); ArrayList list = new ArrayList<>(); - for (String key : jobDataMap.keySet()) { - list.add(toCompositeData(key, String.valueOf(jobDataMap.get(key)))); + for (Map.Entry entry : jobDataMap.entrySet()) { + list.add(toCompositeData(entry.getKey(), String.valueOf(entry.getValue()))); } tData.putAll(list.toArray(new CompositeData[list.size()])); return tData; From 1a81a7e319e520b4d3ec73de439b73990a9840c7 Mon Sep 17 00:00:00 2001 From: Carlos Garcia Date: Wed, 16 Oct 2024 19:33:58 +0200 Subject: [PATCH 12/18] Optimize code, remove some unnecessary initialization, fix some deprecated methods Signed-off-by: Carlos Garcia --- .../impl/jdbcjobstore/StdJDBCDelegate.java | 50 +++++++++---------- 1 file changed, 23 insertions(+), 27 deletions(-) diff --git a/quartz/src/main/java/org/quartz/impl/jdbcjobstore/StdJDBCDelegate.java b/quartz/src/main/java/org/quartz/impl/jdbcjobstore/StdJDBCDelegate.java index 9be39157f..769035272 100644 --- a/quartz/src/main/java/org/quartz/impl/jdbcjobstore/StdJDBCDelegate.java +++ b/quartz/src/main/java/org/quartz/impl/jdbcjobstore/StdJDBCDelegate.java @@ -157,7 +157,7 @@ public void initialize(Logger logger, String tablePrefix, String schedName, Stri for(String trigDelClassName: trigDelegates) { try { Class trigDelClass = classLoadHelper.loadClass(trigDelClassName); - addTriggerPersistenceDelegate((TriggerPersistenceDelegate) trigDelClass.newInstance()); + addTriggerPersistenceDelegate((TriggerPersistenceDelegate) trigDelClass.getDeclaredConstructor().newInstance()); } catch (Exception e) { throw new NoSuchDelegateException("Error instantiating TriggerPersistenceDelegate of type: " + trigDelClassName, e); } @@ -607,7 +607,7 @@ public int insertJobDetail(Connection conn, JobDetail job) PreparedStatement ps = null; - int insertResult = 0; + int insertResult; try { ps = conn.prepareStatement(rtp(INSERT_JOB_DETAIL)); @@ -648,7 +648,7 @@ public int updateJobDetail(Connection conn, JobDetail job) PreparedStatement ps = null; - int insertResult = 0; + int insertResult; try { ps = conn.prepareStatement(rtp(UPDATE_JOB_DETAIL)); @@ -849,7 +849,7 @@ public JobDetail selectJobDetail(Connection conn, JobKey jobKey, job.setDurability(getBoolean(rs, COL_IS_DURABLE)); job.setRequestsRecovery(getBoolean(rs, COL_REQUESTS_RECOVERY)); - Map map = null; + Map map; if (canUseProperties()) { map = getMapFromProperties(rs); } else { @@ -871,20 +871,16 @@ public JobDetail selectJobDetail(Connection conn, JobKey jobKey, /** * build Map from java.util.Properties encoding. */ - private Map getMapFromProperties(ResultSet rs) - throws ClassNotFoundException, IOException, SQLException { + private Map getMapFromProperties(ResultSet rs) throws ClassNotFoundException, IOException, SQLException { Map map; - InputStream is = (InputStream) getJobDataFromBlob(rs, COL_JOB_DATAMAP); - if(is == null) { - return null; - } - Properties properties = new Properties(); - try { + try (InputStream is = (InputStream) getJobDataFromBlob(rs, COL_JOB_DATAMAP)) { + if (is == null) { + return null; + } + Properties properties = new Properties(); properties.load(is); - } finally { - is.close(); + map = convertFromProperty(properties); } - map = convertFromProperty(properties); return map; } @@ -1044,7 +1040,7 @@ public int insertTrigger(Connection conn, OperableTrigger trigger, String state, PreparedStatement ps = null; - int insertResult = 0; + int insertResult; try { ps = conn.prepareStatement(rtp(INSERT_TRIGGER)); @@ -1112,7 +1108,7 @@ public int insertTrigger(Connection conn, OperableTrigger trigger, String state, public int insertBlobTrigger(Connection conn, OperableTrigger trigger) throws SQLException, IOException { PreparedStatement ps = null; - ByteArrayOutputStream os = null; + ByteArrayOutputStream os; try { // update the blob @@ -1160,7 +1156,7 @@ public int updateTrigger(Connection conn, OperableTrigger trigger, String state, PreparedStatement ps = null; - int insertResult = 0; + int insertResult; try { @@ -1758,7 +1754,7 @@ public OperableTrigger selectTrigger(Connection conn, TriggerKey triggerKey) thr int misFireInstr = rs.getInt(COL_MISFIRE_INSTRUCTION); int priority = rs.getInt(COL_PRIORITY); - Map map = null; + Map map; if (canUseProperties()) { map = getMapFromProperties(rs); } else { @@ -1799,7 +1795,7 @@ public OperableTrigger selectTrigger(Connection conn, TriggerKey triggerKey) thr if(tDel == null) throw new JobPersistenceException("No TriggerPersistenceDelegate for trigger discriminator type: " + triggerType); - TriggerPropertyBundle triggerProps = null; + TriggerPropertyBundle triggerProps; try { triggerProps = tDel.loadExtendedTriggerProperties(conn, triggerKey); } catch (IllegalStateException isex) { @@ -1889,7 +1885,7 @@ public JobDataMap selectTriggerJobDataMap(Connection conn, String triggerName, if (rs.next()) { - Map map = null; + Map map; if (canUseProperties()) { map = getMapFromProperties(rs); } else { @@ -1926,7 +1922,7 @@ public String selectTriggerState(Connection conn, TriggerKey triggerKey) throws ResultSet rs = null; try { - String state = null; + String state; ps = conn.prepareStatement(rtp(SELECT_TRIGGER_STATE)); ps.setString(1, triggerKey.getName()); @@ -3071,9 +3067,9 @@ protected ByteArrayOutputStream serializeJobData(JobDataMap data) protected Object getKeyOfNonSerializableValue(Map data) { for (Map.Entry value : data.entrySet()) { - try (ByteArrayOutputStream baos = serializeObject(((Map.Entry) value).getValue())) { + try (ByteArrayOutputStream baos = serializeObject(value.getValue())) { } catch (IOException e) { - return ((Map.Entry) value).getKey(); + return value.getKey(); } } @@ -3099,7 +3095,7 @@ private ByteArrayOutputStream serializeProperties(JobDataMap data) /** * convert the JobDataMap into a list of properties */ - protected Map convertFromProperty(Properties properties) throws IOException { + protected Map convertFromProperty(Properties properties) { return new HashMap<>(properties); } @@ -3111,8 +3107,8 @@ protected Properties convertToProperty(Map data) throws IOException { for (Map.Entry value : data.entrySet()) { - Object key = ((Map.Entry) value).getKey(); - Object val = (((Map.Entry) value).getValue() == null) ? "" : ((Map.Entry) value).getValue(); + Object key = value.getKey(); + Object val = (value.getValue() == null) ? "" : value.getValue(); if (!(key instanceof String)) { throw new IOException("JobDataMap keys/values must be Strings " From 0e9715b0c708725707101cacaf1d68c7197fb267 Mon Sep 17 00:00:00 2001 From: Carlos Garcia Date: Thu, 17 Oct 2024 18:35:11 +0200 Subject: [PATCH 13/18] rollback: Rollback using lambda expressions Signed-off-by: Carlos Garcia --- .../impl/jdbcjobstore/JobStoreSupport.java | 68 +++++++++++++------ 1 file changed, 46 insertions(+), 22 deletions(-) diff --git a/quartz/src/main/java/org/quartz/impl/jdbcjobstore/JobStoreSupport.java b/quartz/src/main/java/org/quartz/impl/jdbcjobstore/JobStoreSupport.java index b58876e59..9d64097dc 100644 --- a/quartz/src/main/java/org/quartz/impl/jdbcjobstore/JobStoreSupport.java +++ b/quartz/src/main/java/org/quartz/impl/jdbcjobstore/JobStoreSupport.java @@ -1246,8 +1246,12 @@ protected boolean triggerExists(Connection conn, TriggerKey key) throws JobPersi public boolean removeJob(final JobKey jobKey) throws JobPersistenceException { return (Boolean) executeInLock( LOCK_TRIGGER_ACCESS, - (TransactionCallback) conn -> removeJob(conn, jobKey) ? - Boolean.TRUE : Boolean.FALSE); + new TransactionCallback() { + public Object execute(Connection conn) throws JobPersistenceException { + return removeJob(conn, jobKey) ? + Boolean.TRUE : Boolean.FALSE; + } + }); } protected boolean removeJob(Connection conn, final JobKey jobKey) @@ -1270,29 +1274,33 @@ public boolean removeJobs(final List jobKeys) throws JobPersistenceExcep return (Boolean) executeInLock( LOCK_TRIGGER_ACCESS, - (TransactionCallback) conn -> { - boolean allFound = true; + new TransactionCallback() { + public Object execute(Connection conn) throws JobPersistenceException { + boolean allFound = true; - // FUTURE_TODO: make this more efficient with a true bulk operation... - for (JobKey jobKey : jobKeys) - allFound = removeJob(conn, jobKey) && allFound; + // FUTURE_TODO: make this more efficient with a true bulk operation... + for (JobKey jobKey : jobKeys) + allFound = removeJob(conn, jobKey) && allFound; - return allFound ? Boolean.TRUE : Boolean.FALSE; + return allFound ? Boolean.TRUE : Boolean.FALSE; + } }); } - + public boolean removeTriggers(final List triggerKeys) throws JobPersistenceException { return (Boolean) executeInLock( LOCK_TRIGGER_ACCESS, - (TransactionCallback) conn -> { - boolean allFound = true; + new TransactionCallback() { + public Object execute(Connection conn) throws JobPersistenceException { + boolean allFound = true; - // FUTURE_TODO: make this more efficient with a true bulk operation... - for (TriggerKey triggerKey : triggerKeys) - allFound = removeTrigger(conn, triggerKey) && allFound; + // FUTURE_TODO: make this more efficient with a true bulk operation... + for (TriggerKey triggerKey : triggerKeys) + allFound = removeTrigger(conn, triggerKey) && allFound; - return allFound ? Boolean.TRUE : Boolean.FALSE; + return allFound ? Boolean.TRUE : Boolean.FALSE; + } }); } @@ -1398,8 +1406,12 @@ protected JobDetail retrieveJob(Connection conn, JobKey key) throws JobPersisten public boolean removeTrigger(final TriggerKey triggerKey) throws JobPersistenceException { return (Boolean) executeInLock( LOCK_TRIGGER_ACCESS, - (TransactionCallback) conn -> removeTrigger(conn, triggerKey) ? - Boolean.TRUE : Boolean.FALSE); + new TransactionCallback() { + public Object execute(Connection conn) throws JobPersistenceException { + return removeTrigger(conn, triggerKey) ? + Boolean.TRUE : Boolean.FALSE; + } + }); } protected boolean removeTrigger(Connection conn, TriggerKey key) @@ -1437,8 +1449,12 @@ public boolean replaceTrigger(final TriggerKey triggerKey, final OperableTrigger newTrigger) throws JobPersistenceException { return (Boolean) executeInLock( LOCK_TRIGGER_ACCESS, - (TransactionCallback) conn -> replaceTrigger(conn, triggerKey, newTrigger) ? - Boolean.TRUE : Boolean.FALSE); + new TransactionCallback() { + public Object execute(Connection conn) throws JobPersistenceException { + return replaceTrigger(conn, triggerKey, newTrigger) ? + Boolean.TRUE : Boolean.FALSE; + } + }); } protected boolean replaceTrigger(Connection conn, @@ -1479,7 +1495,11 @@ protected boolean replaceTrigger(Connection conn, */ public OperableTrigger retrieveTrigger(final TriggerKey triggerKey) throws JobPersistenceException { return (OperableTrigger)executeWithoutLock( // no locks necessary for read... - (TransactionCallback) conn -> retrieveTrigger(conn, triggerKey)); + new TransactionCallback() { + public Object execute(Connection conn) throws JobPersistenceException { + return retrieveTrigger(conn, triggerKey); + } + }); } protected OperableTrigger retrieveTrigger(Connection conn, TriggerKey key) @@ -1686,8 +1706,12 @@ public boolean removeCalendar(final String calName) throws JobPersistenceException { return (Boolean) executeInLock( LOCK_TRIGGER_ACCESS, - (TransactionCallback) conn -> removeCalendar(conn, calName) ? - Boolean.TRUE : Boolean.FALSE); + new TransactionCallback() { + public Object execute(Connection conn) throws JobPersistenceException { + return removeCalendar(conn, calName) ? + Boolean.TRUE : Boolean.FALSE; + } + }); } protected boolean removeCalendar(Connection conn, From a61365b5586a1667390ee8a15f670d72a5d3568b Mon Sep 17 00:00:00 2001 From: Carlos Garcia Date: Thu, 17 Oct 2024 19:00:21 +0200 Subject: [PATCH 14/18] rollback: Rollback using replacing while by enhanced for Signed-off-by: Carlos Garcia --- .../xml/XMLSchedulingDataProcessorPlugin.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/quartz/src/main/java/org/quartz/plugins/xml/XMLSchedulingDataProcessorPlugin.java b/quartz/src/main/java/org/quartz/plugins/xml/XMLSchedulingDataProcessorPlugin.java index c37314e93..4e25e5a8b 100644 --- a/quartz/src/main/java/org/quartz/plugins/xml/XMLSchedulingDataProcessorPlugin.java +++ b/quartz/src/main/java/org/quartz/plugins/xml/XMLSchedulingDataProcessorPlugin.java @@ -26,6 +26,7 @@ import java.net.URLDecoder; import java.nio.charset.StandardCharsets; import java.util.HashSet; +import java.util.Iterator; import java.util.LinkedHashMap; import java.util.Map; import java.util.Set; @@ -214,7 +215,10 @@ public void start(UserTransaction userTransaction) { getScheduler().getContext().put(JOB_INITIALIZATION_PLUGIN_NAME + '_' + getName(), this); } - for (JobFile jobFile : jobFiles.values()) { + Iterator iterator = jobFiles.values().iterator(); + while (iterator.hasNext()) { + JobFile jobFile = iterator.next(); + if (scanInterval > 0) { String jobTriggerName = buildJobTriggerName(jobFile.getFileBasename()); TriggerKey tKey = new TriggerKey(jobTriggerName, JOB_INITIALIZATION_PLUGIN_NAME); @@ -223,12 +227,12 @@ public void start(UserTransaction userTransaction) { getScheduler().unscheduleJob(tKey); JobDetail job = newJob().withIdentity(jobTriggerName, JOB_INITIALIZATION_PLUGIN_NAME).ofType(FileScanJob.class) - .usingJobData(FileScanJob.FILE_NAME, jobFile.getFileName()) - .usingJobData(FileScanJob.FILE_SCAN_LISTENER_NAME, JOB_INITIALIZATION_PLUGIN_NAME + '_' + getName()) - .build(); + .usingJobData(FileScanJob.FILE_NAME, jobFile.getFileName()) + .usingJobData(FileScanJob.FILE_SCAN_LISTENER_NAME, JOB_INITIALIZATION_PLUGIN_NAME + '_' + getName()) + .build(); SimpleTrigger trig = newTrigger().withIdentity(tKey).withSchedule( - simpleSchedule().repeatForever().withIntervalInMilliseconds(scanInterval)) + simpleSchedule().repeatForever().withIntervalInMilliseconds(scanInterval)) .forJob(job) .build(); From f9f248ebee3cda6206612673e5dd318e91eb9641 Mon Sep 17 00:00:00 2001 From: Carlos Garcia Date: Fri, 25 Oct 2024 19:41:19 +0200 Subject: [PATCH 15/18] refactor: Update try-catch Signed-off-by: Carlos Garcia --- .../java/org/quartz/impl/jdbcjobstore/StdJDBCDelegate.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/quartz/src/main/java/org/quartz/impl/jdbcjobstore/StdJDBCDelegate.java b/quartz/src/main/java/org/quartz/impl/jdbcjobstore/StdJDBCDelegate.java index 769035272..48760a798 100644 --- a/quartz/src/main/java/org/quartz/impl/jdbcjobstore/StdJDBCDelegate.java +++ b/quartz/src/main/java/org/quartz/impl/jdbcjobstore/StdJDBCDelegate.java @@ -3067,7 +3067,8 @@ protected ByteArrayOutputStream serializeJobData(JobDataMap data) protected Object getKeyOfNonSerializableValue(Map data) { for (Map.Entry value : data.entrySet()) { - try (ByteArrayOutputStream baos = serializeObject(value.getValue())) { + try { + serializeObject(value.getValue()).close(); } catch (IOException e) { return value.getKey(); } From 1fd04872b5c33d087fd3bb3456865370dd277e15 Mon Sep 17 00:00:00 2001 From: Carlos Garcia Date: Fri, 25 Oct 2024 19:54:26 +0200 Subject: [PATCH 16/18] refactor: Update loadClass Signed-off-by: Carlos Garcia --- .../simpl/CascadingClassLoadHelper.java | 25 ++++++------------- 1 file changed, 7 insertions(+), 18 deletions(-) diff --git a/quartz/src/main/java/org/quartz/simpl/CascadingClassLoadHelper.java b/quartz/src/main/java/org/quartz/simpl/CascadingClassLoadHelper.java index fbbfeca45..8bb696696 100644 --- a/quartz/src/main/java/org/quartz/simpl/CascadingClassLoadHelper.java +++ b/quartz/src/main/java/org/quartz/simpl/CascadingClassLoadHelper.java @@ -93,7 +93,6 @@ public void initialize() { * Return the class with the given name. */ public Class loadClass(String name) throws ClassNotFoundException { - if (bestCandidate != null) { try { return bestCandidate.loadClass(name); @@ -103,32 +102,22 @@ public Class loadClass(String name) throws ClassNotFoundException { } Throwable throwable = null; - Class clazz = null; - ClassLoadHelper loadHelper = null; for (ClassLoadHelper helper : loadHelpers) { - loadHelper = helper; - try { - clazz = loadHelper.loadClass(name); - break; + Class clazz = helper.loadClass(name); + bestCandidate = helper; + return clazz; } catch (Throwable t) { throwable = t; } } - if (clazz == null) { - if (throwable instanceof ClassNotFoundException) { - throw (ClassNotFoundException)throwable; - } - else { - throw new ClassNotFoundException( String.format( "Unable to load class %s by any known loaders.", name), throwable); - } + if (throwable instanceof ClassNotFoundException) { + throw (ClassNotFoundException) throwable; + } else { + throw new ClassNotFoundException( String.format( "Unable to load class %s by any known loaders.", name), throwable); } - - bestCandidate = loadHelper; - - return clazz; } @SuppressWarnings("unchecked") From 3995a52ca589bd23f33225fe26cf10004310aee5 Mon Sep 17 00:00:00 2001 From: Carlos Garcia Date: Fri, 25 Oct 2024 20:20:51 +0200 Subject: [PATCH 17/18] fix: Fix bug at creating exception message Signed-off-by: Carlos Garcia --- .../java/org/quartz/xml/ValidationException.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/quartz/src/main/java/org/quartz/xml/ValidationException.java b/quartz/src/main/java/org/quartz/xml/ValidationException.java index 1c3fbf6ac..c9db58a74 100644 --- a/quartz/src/main/java/org/quartz/xml/ValidationException.java +++ b/quartz/src/main/java/org/quartz/xml/ValidationException.java @@ -121,16 +121,20 @@ public Collection getValidationExceptions() { public String getMessage() { if (getValidationExceptions().isEmpty()) { return super.getMessage(); } - StringBuffer sb = new StringBuffer(); + StringBuilder messageBuilder = new StringBuilder(); - boolean first = true; + boolean isFirst = true; for (Exception e : getValidationExceptions()) { + if (!isFirst) { + messageBuilder.append('\n'); + } + isFirst = false; - sb.append(e.getMessage()); + messageBuilder.append(e.getMessage()); } - return sb.toString(); + return messageBuilder.toString(); } From bf8636a6e271d3e237e0c43c358a367a9de1c561 Mon Sep 17 00:00:00 2001 From: Carlos Garcia Date: Fri, 25 Oct 2024 20:43:50 +0200 Subject: [PATCH 18/18] refactor: Use lambda to simplify code Signed-off-by: Carlos Garcia --- .../impl/jdbcjobstore/JobStoreSupport.java | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/quartz/src/main/java/org/quartz/impl/jdbcjobstore/JobStoreSupport.java b/quartz/src/main/java/org/quartz/impl/jdbcjobstore/JobStoreSupport.java index 2b72990d7..a18df912a 100644 --- a/quartz/src/main/java/org/quartz/impl/jdbcjobstore/JobStoreSupport.java +++ b/quartz/src/main/java/org/quartz/impl/jdbcjobstore/JobStoreSupport.java @@ -1292,18 +1292,16 @@ public Object execute(Connection conn) throws JobPersistenceException { public boolean removeTriggers(final List triggerKeys) throws JobPersistenceException { - return (Boolean) executeInLock( + return executeInLock( LOCK_TRIGGER_ACCESS, - new TransactionCallback() { - public Object execute(Connection conn) throws JobPersistenceException { - boolean allFound = true; + conn -> { + boolean allFound = true; - // FUTURE_TODO: make this more efficient with a true bulk operation... - for (TriggerKey triggerKey : triggerKeys) - allFound = removeTrigger(conn, triggerKey) && allFound; + // FUTURE_TODO: make this more efficient with a true bulk operation... + for (TriggerKey triggerKey : triggerKeys) + allFound &= removeTrigger(conn, triggerKey); - return allFound ? Boolean.TRUE : Boolean.FALSE; - } + return allFound; }); }