Browse Source

SchedulerAccessor catches cluster race conditions on job rescheduling

Issue: SPR-17114

(cherry picked from commit fa97aab8be)
pull/1935/head
Juergen Hoeller 8 years ago
parent
commit
7da02fb7e3
  1. 18
      spring-context-support/src/main/java/org/springframework/scheduling/quartz/SchedulerAccessor.java

18
spring-context-support/src/main/java/org/springframework/scheduling/quartz/SchedulerAccessor.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -131,7 +131,7 @@ public abstract class SchedulerAccessor implements ResourceLoaderAware { @@ -131,7 +131,7 @@ public abstract class SchedulerAccessor implements ResourceLoaderAware {
/**
* Register a list of Quartz Calendar objects with the Scheduler
* that this FactoryBean creates, to be referenced by Triggers.
* @param calendars Map with calendar names as keys as Calendar
* @param calendars a Map with calendar names as keys as Calendar
* objects as values
* @see org.quartz.Calendar
*/
@ -299,7 +299,15 @@ public abstract class SchedulerAccessor implements ResourceLoaderAware { @@ -299,7 +299,15 @@ public abstract class SchedulerAccessor implements ResourceLoaderAware {
if (jobDetail != null && !this.jobDetails.contains(jobDetail) && addJobToScheduler(jobDetail)) {
this.jobDetails.add(jobDetail);
}
getScheduler().rescheduleJob(trigger.getKey(), trigger);
try {
getScheduler().rescheduleJob(trigger.getKey(), trigger);
}
catch (ObjectAlreadyExistsException ex) {
if (logger.isDebugEnabled()) {
logger.debug("Unexpectedly encountered existing trigger on rescheduling, assumably due to " +
"cluster race condition: " + ex.getMessage() + " - can safely be ignored");
}
}
}
else {
try {
@ -314,8 +322,8 @@ public abstract class SchedulerAccessor implements ResourceLoaderAware { @@ -314,8 +322,8 @@ public abstract class SchedulerAccessor implements ResourceLoaderAware {
}
catch (ObjectAlreadyExistsException ex) {
if (logger.isDebugEnabled()) {
logger.debug("Unexpectedly found existing trigger, assumably due to cluster race condition: " +
ex.getMessage() + " - can safely be ignored");
logger.debug("Unexpectedly encountered existing trigger on job scheduling, assumably due to " +
"cluster race condition: " + ex.getMessage() + " - can safely be ignored");
}
if (this.overwriteExistingJobs) {
getScheduler().rescheduleJob(trigger.getKey(), trigger);

Loading…
Cancel
Save