Skip to content

Commit ae1ed9d

Browse files
committed
Document exception handling limitations in TaskDecorator implementations
Closes gh-25231
1 parent 8697026 commit ae1ed9d

File tree

8 files changed

+54
-14
lines changed

8 files changed

+54
-14
lines changed

spring-context-support/src/main/java/org/springframework/scheduling/commonj/WorkManagerTaskExecutor.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -58,13 +58,13 @@
5858
* <p>The CommonJ WorkManager will usually be retrieved from the application
5959
* server's JNDI environment, as defined in the server's management console.
6060
*
61-
* <p>Note: On the upcoming EE 7 compliant versions of WebLogic and WebSphere, a
61+
* <p>Note: On EE 7/8 compliant versions of WebLogic and WebSphere, a
6262
* {@link org.springframework.scheduling.concurrent.DefaultManagedTaskExecutor}
63-
* should be preferred, following JSR-236 support in Java EE 7.
63+
* should be preferred, following JSR-236 support in Java EE 7/8.
6464
*
6565
* @author Juergen Hoeller
6666
* @since 2.0
67-
* @deprecated as of 5.1, in favor of EE 7's
67+
* @deprecated as of 5.1, in favor of the EE 7/8 based
6868
* {@link org.springframework.scheduling.concurrent.DefaultManagedTaskExecutor}
6969
*/
7070
@Deprecated
@@ -121,6 +121,11 @@ public void setWorkListener(WorkListener workListener) {
121121
* execution callback (which may be a wrapper around the user-supplied task).
122122
* <p>The primary use case is to set some execution context around the task's
123123
* invocation, or to provide some monitoring/statistics for task execution.
124+
* <p><b>NOTE:</b> Exception handling in {@code TaskDecorator} implementations
125+
* is limited to plain {@code Runnable} execution via {@code execute} calls.
126+
* In case of {@code #submit} calls, the exposed {@code Runnable} will be a
127+
* {@code FutureTask} which does not propagate any exceptions; you might
128+
* have to cast it and call {@code Future#get} to evaluate exceptions.
124129
* @since 4.3
125130
*/
126131
public void setTaskDecorator(TaskDecorator taskDecorator) {

spring-context/src/main/java/org/springframework/scheduling/concurrent/ConcurrentTaskExecutor.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -130,6 +130,11 @@ public final Executor getConcurrentExecutor() {
130130
* execution callback (which may be a wrapper around the user-supplied task).
131131
* <p>The primary use case is to set some execution context around the task's
132132
* invocation, or to provide some monitoring/statistics for task execution.
133+
* <p><b>NOTE:</b> Exception handling in {@code TaskDecorator} implementations
134+
* is limited to plain {@code Runnable} execution via {@code execute} calls.
135+
* In case of {@code #submit} calls, the exposed {@code Runnable} will be a
136+
* {@code FutureTask} which does not propagate any exceptions; you might
137+
* have to cast it and call {@code Future#get} to evaluate exceptions.
133138
* @since 4.3
134139
*/
135140
public final void setTaskDecorator(TaskDecorator taskDecorator) {

spring-context/src/main/java/org/springframework/scheduling/concurrent/DefaultManagedTaskExecutor.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -28,7 +28,7 @@
2828

2929
/**
3030
* JNDI-based variant of {@link ConcurrentTaskExecutor}, performing a default lookup for
31-
* JSR-236's "java:comp/DefaultManagedExecutorService" in a Java EE 7 environment.
31+
* JSR-236's "java:comp/DefaultManagedExecutorService" in a Java EE 7/8 environment.
3232
*
3333
* <p>Note: This class is not strictly JSR-236 based; it can work with any regular
3434
* {@link java.util.concurrent.Executor} that can be found in JNDI.
@@ -37,10 +37,11 @@
3737
*
3838
* @author Juergen Hoeller
3939
* @since 4.0
40+
* @see javax.enterprise.concurrent.ManagedExecutorService
4041
*/
4142
public class DefaultManagedTaskExecutor extends ConcurrentTaskExecutor implements InitializingBean {
4243

43-
private JndiLocatorDelegate jndiLocator = new JndiLocatorDelegate();
44+
private final JndiLocatorDelegate jndiLocator = new JndiLocatorDelegate();
4445

4546
@Nullable
4647
private String jndiName = "java:comp/DefaultManagedExecutorService";

spring-context/src/main/java/org/springframework/scheduling/concurrent/ThreadPoolTaskExecutor.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -205,6 +205,13 @@ public void setAllowCoreThreadTimeOut(boolean allowCoreThreadTimeOut) {
205205
* execution callback (which may be a wrapper around the user-supplied task).
206206
* <p>The primary use case is to set some execution context around the task's
207207
* invocation, or to provide some monitoring/statistics for task execution.
208+
* <p><b>NOTE:</b> Exception handling in {@code TaskDecorator} implementations
209+
* is limited to plain {@code Runnable} execution via {@code execute} calls.
210+
* In case of {@code #submit} calls, the exposed {@code Runnable} will be a
211+
* {@code FutureTask} which does not propagate any exceptions; you might
212+
* have to cast it and call {@code Future#get} to evaluate exceptions.
213+
* See the {@code ThreadPoolExecutor#afterExecute} javadoc for an example
214+
* of how to access exceptions in such a {@code Future} case.
208215
* @since 4.3
209216
*/
210217
public void setTaskDecorator(TaskDecorator taskDecorator) {

spring-core/src/main/java/org/springframework/core/task/SimpleAsyncTaskExecutor.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -126,6 +126,11 @@ public final ThreadFactory getThreadFactory() {
126126
* execution callback (which may be a wrapper around the user-supplied task).
127127
* <p>The primary use case is to set some execution context around the task's
128128
* invocation, or to provide some monitoring/statistics for task execution.
129+
* <p><b>NOTE:</b> Exception handling in {@code TaskDecorator} implementations
130+
* is limited to plain {@code Runnable} execution via {@code execute} calls.
131+
* In case of {@code #submit} calls, the exposed {@code Runnable} will be a
132+
* {@code FutureTask} which does not propagate any exceptions; you might
133+
* have to cast it and call {@code Future#get} to evaluate exceptions.
129134
* @since 4.3
130135
*/
131136
public final void setTaskDecorator(TaskDecorator taskDecorator) {

spring-core/src/main/java/org/springframework/core/task/TaskDecorator.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -27,17 +27,24 @@
2727
* <p>The primary use case is to set some execution context around the task's
2828
* invocation, or to provide some monitoring/statistics for task execution.
2929
*
30+
* <p><b>NOTE:</b> Exception handling in {@code TaskDecorator} implementations
31+
* may be limited. Specifically in case of a {@code Future}-based operation,
32+
* the exposed {@code Runnable} will be a wrapper which does not propagate
33+
* any exceptions from its {@code run} method.
34+
*
3035
* @author Juergen Hoeller
3136
* @since 4.3
3237
* @see TaskExecutor#execute(Runnable)
3338
* @see SimpleAsyncTaskExecutor#setTaskDecorator
39+
* @see org.springframework.core.task.support.TaskExecutorAdapter#setTaskDecorator
3440
*/
3541
@FunctionalInterface
3642
public interface TaskDecorator {
3743

3844
/**
3945
* Decorate the given {@code Runnable}, returning a potentially wrapped
40-
* {@code Runnable} for actual execution.
46+
* {@code Runnable} for actual execution, internally delegating to the
47+
* original {@link Runnable#run()} implementation.
4148
* @param runnable the original {@code Runnable}
4249
* @return the decorated {@code Runnable}
4350
*/

spring-core/src/main/java/org/springframework/core/task/support/TaskExecutorAdapter.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -70,6 +70,11 @@ public TaskExecutorAdapter(Executor concurrentExecutor) {
7070
* execution callback (which may be a wrapper around the user-supplied task).
7171
* <p>The primary use case is to set some execution context around the task's
7272
* invocation, or to provide some monitoring/statistics for task execution.
73+
* <p><b>NOTE:</b> Exception handling in {@code TaskDecorator} implementations
74+
* is limited to plain {@code Runnable} execution via {@code execute} calls.
75+
* In case of {@code #submit} calls, the exposed {@code Runnable} will be a
76+
* {@code FutureTask} which does not propagate any exceptions; you might
77+
* have to cast it and call {@code Future#get} to evaluate exceptions.
7378
* @since 4.3
7479
*/
7580
public final void setTaskDecorator(TaskDecorator taskDecorator) {

spring-tx/src/main/java/org/springframework/jca/work/WorkManagerTaskExecutor.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -175,6 +175,11 @@ public void setWorkListener(@Nullable WorkListener workListener) {
175175
* execution callback (which may be a wrapper around the user-supplied task).
176176
* <p>The primary use case is to set some execution context around the task's
177177
* invocation, or to provide some monitoring/statistics for task execution.
178+
* <p><b>NOTE:</b> Exception handling in {@code TaskDecorator} implementations
179+
* is limited to plain {@code Runnable} execution via {@code execute} calls.
180+
* In case of {@code #submit} calls, the exposed {@code Runnable} will be a
181+
* {@code FutureTask} which does not propagate any exceptions; you might
182+
* have to cast it and call {@code Future#get} to evaluate exceptions.
178183
* @since 4.3
179184
*/
180185
public void setTaskDecorator(TaskDecorator taskDecorator) {

0 commit comments

Comments
 (0)