Skip to content

Commit

Permalink
Added an explicit way to set ExecuteExistingDelayedTasksAfterShutdown…
Browse files Browse the repository at this point in the history
… property.

This closes an existing issue:
spring-projects#26719
  • Loading branch information
aelykto committed Apr 15, 2021
1 parent 27c4e74 commit f179d53
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion gradle.properties
@@ -1,5 +1,5 @@
version=5.3.7-SNAPSHOT
org.gradle.jvmargs=-Xmx1536M
#org.gradle.jvmargs=-Xmx1536M
org.gradle.caching=true
org.gradle.parallel=true
kotlin.stdlib.default.dependency=false
Expand Up @@ -64,6 +64,8 @@ public class ThreadPoolTaskScheduler extends ExecutorConfigurationSupport

private volatile boolean removeOnCancelPolicy;

private volatile boolean executeExistingDelayedTasksAfterShutdownPolicy;

@Nullable
private volatile ErrorHandler errorHandler;

Expand Down Expand Up @@ -106,6 +108,23 @@ else if (removeOnCancelPolicy && this.scheduledExecutor != null) {
}
}

/**
* Set the execute-existing-delayed-tasks-after-shutdown mode on {@link ScheduledThreadPoolExecutor}.
* <p>Default is {@code true}. If set to {@code false}, the target executor will be
* switched into execute-existing-delayed-tasks-after-shutdown.
* <p><b>This setting can be modified at runtime, for example through JMX.</b>
*/
public void setExecuteExistingDelayedTasksAfterShutdownPolicy(boolean executeExistingDelayedTasksAfterShutdownPolicy) {
this.executeExistingDelayedTasksAfterShutdownPolicy = executeExistingDelayedTasksAfterShutdownPolicy;
if (this.scheduledExecutor instanceof ScheduledThreadPoolExecutor) {
((ScheduledThreadPoolExecutor) this.scheduledExecutor)
.setExecuteExistingDelayedTasksAfterShutdownPolicy(executeExistingDelayedTasksAfterShutdownPolicy);
}
else if (executeExistingDelayedTasksAfterShutdownPolicy && this.scheduledExecutor != null) {
logger.debug("Could not apply execute-existing-delayed-tasks-after-shutdown policy - not a ScheduledThreadPoolExecutor");
}
}

/**
* Set a custom {@link ErrorHandler} strategy.
*/
Expand Down

0 comments on commit f179d53

Please sign in to comment.