Polishing

This commit is contained in:
Juergen Hoeller
2014-09-26 22:38:41 +02:00
parent a6e1c53f23
commit 7f9baa3a09
4 changed files with 30 additions and 39 deletions

View File

@@ -58,7 +58,7 @@ import org.springframework.util.ObjectUtils;
* @author Juergen Hoeller
* @since 2.0
* @see #setPoolSize
* @see #setRemoveOnCancelPolicy(boolean)
* @see #setRemoveOnCancelPolicy
* @see #setThreadFactory
* @see ScheduledExecutorTask
* @see java.util.concurrent.ScheduledExecutorService
@@ -68,17 +68,17 @@ import org.springframework.util.ObjectUtils;
public class ScheduledExecutorFactoryBean extends ExecutorConfigurationSupport
implements FactoryBean<ScheduledExecutorService> {
// ScheduledThreadPoolExecutor.setRemoveOnCancelPolicy(boolean) only available on JDK 1.7+
// ScheduledThreadPoolExecutor.setRemoveOnCancelPolicy(boolean) only available on JDK 7+
private static final boolean setRemoveOnCancelPolicyAvailable =
ClassUtils.hasMethod(ScheduledThreadPoolExecutor.class, "setRemoveOnCancelPolicy", boolean.class);
private int poolSize = 1;
private boolean removeOnCancelPolicy;
private ScheduledExecutorTask[] scheduledExecutorTasks;
private boolean removeOnCancelPolicy = false;
private boolean continueScheduledExecutionAfterException = false;
private boolean exposeUnconfigurableExecutor = false;
@@ -95,14 +95,6 @@ public class ScheduledExecutorFactoryBean extends ExecutorConfigurationSupport
this.poolSize = poolSize;
}
/**
* Set the same property on ScheduledExecutorService (JDK 1.7+).
* There is no default. If not set, the executor property is not set.
*/
public void setRemoveOnCancelPolicy(boolean removeOnCancelPolicy) {
this.removeOnCancelPolicy = removeOnCancelPolicy;
}
/**
* Register a list of ScheduledExecutorTask objects with the ScheduledExecutorService
* that this FactoryBean creates. Depending on each ScheduledExecutorTask's settings,
@@ -115,6 +107,15 @@ public class ScheduledExecutorFactoryBean extends ExecutorConfigurationSupport
this.scheduledExecutorTasks = scheduledExecutorTasks;
}
/**
* Set the remove-on-cancel mode on {@link ScheduledThreadPoolExecutor} (JDK 7+).
* <p>Default is {@code false}. If set to {@code true}, the target executor will be
* switched into remove-on-cancel mode (if possible, with a soft fallback otherwise).
*/
public void setRemoveOnCancelPolicy(boolean removeOnCancelPolicy) {
this.removeOnCancelPolicy = removeOnCancelPolicy;
}
/**
* Specify whether to continue the execution of a scheduled task
* after it threw an exception.

View File

@@ -58,14 +58,14 @@ import org.springframework.util.concurrent.ListenableFutureTask;
public class ThreadPoolTaskScheduler extends ExecutorConfigurationSupport
implements AsyncListenableTaskExecutor, SchedulingTaskExecutor, TaskScheduler {
// ScheduledThreadPoolExecutor.setRemoveOnCancelPolicy(boolean) only available on JDK 1.7+
// ScheduledThreadPoolExecutor.setRemoveOnCancelPolicy(boolean) only available on JDK 7+
private static final boolean setRemoveOnCancelPolicyAvailable =
ClassUtils.hasMethod(ScheduledThreadPoolExecutor.class, "setRemoveOnCancelPolicy", boolean.class);
private volatile int poolSize = 1;
private volatile boolean removeOnCancelPolicy;
private volatile boolean removeOnCancelPolicy = false;
private volatile ScheduledExecutorService scheduledExecutor;
@@ -86,8 +86,9 @@ public class ThreadPoolTaskScheduler extends ExecutorConfigurationSupport
}
/**
* Set the same property on ScheduledExecutorService (JDK 1.7+).
* There is no default. If not set, the executor property is not set.
* Set the remove-on-cancel mode on {@link ScheduledThreadPoolExecutor} (JDK 7+).
* <p>Default is {@code false}. If set to {@code true}, the target executor will be
* switched into remove-on-cancel mode (if possible, with a soft fallback otherwise).
* <p><b>This setting can be modified at runtime, for example through JMX.</b>
*/
@UsesJava7
@@ -183,14 +184,17 @@ public class ThreadPoolTaskScheduler extends ExecutorConfigurationSupport
}
/**
* Return the current setting of removeOnCancelPolicy.
* <p>Requires an underlying {@link ScheduledThreadPoolExecutor} and JDK 1.7+.
* Return the current setting for the remove-on-cancel mode.
* <p>Requires an underlying {@link ScheduledThreadPoolExecutor}.
*/
@UsesJava7
public boolean isRemoveOnCancelPolicy() {
if (!setRemoveOnCancelPolicyAvailable) {
return false;
}
if (this.scheduledExecutor == null) {
// Not initialized yet: return our setting for the time being.
return (setRemoveOnCancelPolicyAvailable && this.removeOnCancelPolicy);
return this.removeOnCancelPolicy;
}
return getScheduledThreadPoolExecutor().getRemoveOnCancelPolicy();
}