From 547425275ce66cfd6ac143663068512bc420549d Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Fri, 15 Mar 2024 21:16:37 +0100 Subject: [PATCH] Consistently apply TaskDecorator to ManagedExecutorService as well Closes gh-32455 --- .../concurrent/ConcurrentTaskExecutor.java | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/spring-context/src/main/java/org/springframework/scheduling/concurrent/ConcurrentTaskExecutor.java b/spring-context/src/main/java/org/springframework/scheduling/concurrent/ConcurrentTaskExecutor.java index f0fd31a8abd1..a9033e518229 100644 --- a/spring-context/src/main/java/org/springframework/scheduling/concurrent/ConcurrentTaskExecutor.java +++ b/spring-context/src/main/java/org/springframework/scheduling/concurrent/ConcurrentTaskExecutor.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -134,11 +134,6 @@ public final Executor getConcurrentExecutor() { * execution callback (which may be a wrapper around the user-supplied task). *

The primary use case is to set some execution context around the task's * invocation, or to provide some monitoring/statistics for task execution. - *

NOTE: Exception handling in {@code TaskDecorator} implementations - * is limited to plain {@code Runnable} execution via {@code execute} calls. - * In case of {@code #submit} calls, the exposed {@code Runnable} will be a - * {@code FutureTask} which does not propagate any exceptions; you might - * have to cast it and call {@code Future#get} to evaluate exceptions. * @since 4.3 */ public final void setTaskDecorator(TaskDecorator taskDecorator) { @@ -179,11 +174,10 @@ public ListenableFuture submitListenable(Callable task) { } - private TaskExecutorAdapter getAdaptedExecutor(Executor concurrentExecutor) { - if (managedExecutorServiceClass != null && managedExecutorServiceClass.isInstance(concurrentExecutor)) { - return new ManagedTaskExecutorAdapter(concurrentExecutor); - } - TaskExecutorAdapter adapter = new TaskExecutorAdapter(concurrentExecutor); + private TaskExecutorAdapter getAdaptedExecutor(Executor originalExecutor) { + TaskExecutorAdapter adapter = + (managedExecutorServiceClass != null && managedExecutorServiceClass.isInstance(originalExecutor) ? + new ManagedTaskExecutorAdapter(originalExecutor) : new TaskExecutorAdapter(originalExecutor)); if (this.taskDecorator != null) { adapter.setTaskDecorator(this.taskDecorator); }