Skip to content

Commit 323977b

Browse files
committed
Document exception handling limitations in TaskDecorator implementations
Closes gh-25231
1 parent 2c1cca6 commit 323977b

File tree

8 files changed

+53
-13
lines changed

8 files changed

+53
-13
lines changed

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

Lines changed: 8 additions & 3 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.
@@ -56,9 +56,9 @@
5656
* <p>The CommonJ WorkManager will usually be retrieved from the application
5757
* server's JNDI environment, as defined in the server's management console.
5858
*
59-
* <p>Note: On the upcoming EE 7 compliant versions of WebLogic and WebSphere, a
59+
* <p>Note: On EE 7/8 compliant versions of WebLogic and WebSphere, a
6060
* {@link org.springframework.scheduling.concurrent.DefaultManagedTaskExecutor}
61-
* should be preferred, following JSR-236 support in Java EE 7.
61+
* should be preferred, following JSR-236 support in Java EE 7/8.
6262
*
6363
* @author Juergen Hoeller
6464
* @since 2.0
@@ -112,6 +112,11 @@ public void setWorkListener(WorkListener workListener) {
112112
* execution callback (which may be a wrapper around the user-supplied task).
113113
* <p>The primary use case is to set some execution context around the task's
114114
* invocation, or to provide some monitoring/statistics for task execution.
115+
* <p><b>NOTE:</b> Exception handling in {@code TaskDecorator} implementations
116+
* is limited to plain {@code Runnable} execution via {@code execute} calls.
117+
* In case of {@code #submit} calls, the exposed {@code Runnable} will be a
118+
* {@code FutureTask} which does not propagate any exceptions; you might
119+
* have to cast it and call {@code Future#get} to evaluate exceptions.
115120
* @since 4.3
116121
*/
117122
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-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.
@@ -136,6 +136,11 @@ public final Executor getConcurrentExecutor() {
136136
* execution callback (which may be a wrapper around the user-supplied task).
137137
* <p>The primary use case is to set some execution context around the task's
138138
* invocation, or to provide some monitoring/statistics for task execution.
139+
* <p><b>NOTE:</b> Exception handling in {@code TaskDecorator} implementations
140+
* is limited to plain {@code Runnable} execution via {@code execute} calls.
141+
* In case of {@code #submit} calls, the exposed {@code Runnable} will be a
142+
* {@code FutureTask} which does not propagate any exceptions; you might
143+
* have to cast it and call {@code Future#get} to evaluate exceptions.
139144
* @since 4.3
140145
*/
141146
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-2013 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.
@@ -26,7 +26,7 @@
2626

2727
/**
2828
* JNDI-based variant of {@link ConcurrentTaskExecutor}, performing a default lookup for
29-
* JSR-236's "java:comp/DefaultManagedExecutorService" in a Java EE 7 environment.
29+
* JSR-236's "java:comp/DefaultManagedExecutorService" in a Java EE 7/8 environment.
3030
*
3131
* <p>Note: This class is not strictly JSR-236 based; it can work with any regular
3232
* {@link java.util.concurrent.Executor} that can be found in JNDI.
@@ -35,10 +35,11 @@
3535
*
3636
* @author Juergen Hoeller
3737
* @since 4.0
38+
* @see javax.enterprise.concurrent.ManagedExecutorService
3839
*/
3940
public class DefaultManagedTaskExecutor extends ConcurrentTaskExecutor implements InitializingBean {
4041

41-
private JndiLocatorDelegate jndiLocator = new JndiLocatorDelegate();
42+
private final JndiLocatorDelegate jndiLocator = new JndiLocatorDelegate();
4243

4344
private String jndiName = "java:comp/DefaultManagedExecutorService";
4445

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.
@@ -196,6 +196,13 @@ public void setAllowCoreThreadTimeOut(boolean allowCoreThreadTimeOut) {
196196
* execution callback (which may be a wrapper around the user-supplied task).
197197
* <p>The primary use case is to set some execution context around the task's
198198
* invocation, or to provide some monitoring/statistics for task execution.
199+
* <p><b>NOTE:</b> Exception handling in {@code TaskDecorator} implementations
200+
* is limited to plain {@code Runnable} execution via {@code execute} calls.
201+
* In case of {@code #submit} calls, the exposed {@code Runnable} will be a
202+
* {@code FutureTask} which does not propagate any exceptions; you might
203+
* have to cast it and call {@code Future#get} to evaluate exceptions.
204+
* See the {@code ThreadPoolExecutor#afterExecute} javadoc for an example
205+
* of how to access exceptions in such a {@code Future} case.
199206
* @since 4.3
200207
*/
201208
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-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.
@@ -122,6 +122,11 @@ public final ThreadFactory getThreadFactory() {
122122
* execution callback (which may be a wrapper around the user-supplied task).
123123
* <p>The primary use case is to set some execution context around the task's
124124
* invocation, or to provide some monitoring/statistics for task execution.
125+
* <p><b>NOTE:</b> Exception handling in {@code TaskDecorator} implementations
126+
* is limited to plain {@code Runnable} execution via {@code execute} calls.
127+
* In case of {@code #submit} calls, the exposed {@code Runnable} will be a
128+
* {@code FutureTask} which does not propagate any exceptions; you might
129+
* have to cast it and call {@code Future#get} to evaluate exceptions.
125130
* @since 4.3
126131
*/
127132
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,16 +27,23 @@
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
public interface TaskDecorator {
3642

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

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.
@@ -68,6 +68,11 @@ public TaskExecutorAdapter(Executor concurrentExecutor) {
6868
* execution callback (which may be a wrapper around the user-supplied task).
6969
* <p>The primary use case is to set some execution context around the task's
7070
* invocation, or to provide some monitoring/statistics for task execution.
71+
* <p><b>NOTE:</b> Exception handling in {@code TaskDecorator} implementations
72+
* is limited to plain {@code Runnable} execution via {@code execute} calls.
73+
* In case of {@code #submit} calls, the exposed {@code Runnable} will be a
74+
* {@code FutureTask} which does not propagate any exceptions; you might
75+
* have to cast it and call {@code Future#get} to evaluate exceptions.
7176
* @since 4.3
7277
*/
7378
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-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.
@@ -175,6 +175,11 @@ public void setWorkListener(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)