Skip to content

Commit

Permalink
Check termination status for TaskSchedulerRouter instances correctly (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
tw-peeterkarolin authored Apr 10, 2024
1 parent 15de556 commit ab385a7
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres
to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [2.14.4] - 2024-04-10

### Fixed

* Check termination status for `TaskSchedulerRouter` instances correctly.

## [2.14.3] - 2024-02-22

### Changed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import org.springframework.context.ApplicationContext;
import org.springframework.scheduling.TaskScheduler;
import org.springframework.scheduling.config.ScheduledTaskRegistrar;
import org.springframework.scheduling.config.Task;
import reactor.core.publisher.Mono;

@Slf4j
Expand Down Expand Up @@ -94,6 +93,8 @@ protected Mono<Boolean> getResourceGracefulTerminationStatus(TaskScheduler resou
return Mono.fromCallable(() -> {
if (resource instanceof Executor) {
return ExecutorShutdownUtils.isTerminated((Executor) resource);
} else if (taskSchedulerRouter != null && taskSchedulerRouter.isInstance(resource)) {
return getTaskSchedulerRouterTerminationStatus(resource);
} else {
log.warn("Unknown TaskScheduler to check termination: {}. Return true.", resource.getClass());
return true;
Expand Down Expand Up @@ -134,4 +135,16 @@ private void shutdownTaskSchedulerRouterForced(TaskScheduler scheduler) {
}
}

private boolean getTaskSchedulerRouterTerminationStatus(TaskScheduler scheduler) {
try {
Executor executor = (Executor) taskSchedulerRouterLocalExecutorField.get(scheduler);
if (executor != null) {
return ExecutorShutdownUtils.isTerminated(executor);
}
} catch (IllegalAccessException e) {
log.warn("Couldn't get TaskSchedulerRouter termination status during graceful shutdown", e);
}
return true;
}

}
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version=2.14.3
version=2.14.4

0 comments on commit ab385a7

Please sign in to comment.