65
65
@ SuppressWarnings ("deprecation" )
66
66
public class ConcurrentTaskExecutor implements AsyncListenableTaskExecutor , SchedulingTaskExecutor {
67
67
68
+ private static final Executor STUB_EXECUTOR = (task -> {
69
+ throw new IllegalStateException ("Executor not configured" );
70
+ });
71
+
68
72
@ Nullable
69
73
private static Class <?> managedExecutorServiceClass ;
70
74
@@ -80,15 +84,22 @@ public class ConcurrentTaskExecutor implements AsyncListenableTaskExecutor, Sche
80
84
}
81
85
}
82
86
83
- private Executor concurrentExecutor ;
84
87
85
- private TaskExecutorAdapter adaptedExecutor ;
88
+ private Executor concurrentExecutor = STUB_EXECUTOR ;
89
+
90
+ private TaskExecutorAdapter adaptedExecutor = new TaskExecutorAdapter (STUB_EXECUTOR );
91
+
92
+ @ Nullable
93
+ private TaskDecorator taskDecorator ;
86
94
87
95
88
96
/**
89
97
* Create a new ConcurrentTaskExecutor, using a single thread executor as default.
90
98
* @see java.util.concurrent.Executors#newSingleThreadExecutor()
99
+ * @deprecated in favor of {@link #ConcurrentTaskExecutor(Executor)} with an
100
+ * externally provided Executor
91
101
*/
102
+ @ Deprecated (since = "6.1" )
92
103
public ConcurrentTaskExecutor () {
93
104
this .concurrentExecutor = Executors .newSingleThreadExecutor ();
94
105
this .adaptedExecutor = new TaskExecutorAdapter (this .concurrentExecutor );
@@ -101,8 +112,9 @@ public ConcurrentTaskExecutor() {
101
112
* @param executor the {@link java.util.concurrent.Executor} to delegate to
102
113
*/
103
114
public ConcurrentTaskExecutor (@ Nullable Executor executor ) {
104
- this .concurrentExecutor = (executor != null ? executor : Executors .newSingleThreadExecutor ());
105
- this .adaptedExecutor = getAdaptedExecutor (this .concurrentExecutor );
115
+ if (executor != null ) {
116
+ setConcurrentExecutor (executor );
117
+ }
106
118
}
107
119
108
120
@@ -111,8 +123,8 @@ public ConcurrentTaskExecutor(@Nullable Executor executor) {
111
123
* <p>Autodetects a JSR-236 {@link jakarta.enterprise.concurrent.ManagedExecutorService}
112
124
* in order to expose {@link jakarta.enterprise.concurrent.ManagedTask} adapters for it.
113
125
*/
114
- public final void setConcurrentExecutor (@ Nullable Executor executor ) {
115
- this .concurrentExecutor = ( executor != null ? executor : Executors . newSingleThreadExecutor ()) ;
126
+ public final void setConcurrentExecutor (Executor executor ) {
127
+ this .concurrentExecutor = executor ;
116
128
this .adaptedExecutor = getAdaptedExecutor (this .concurrentExecutor );
117
129
}
118
130
@@ -139,6 +151,7 @@ public final Executor getConcurrentExecutor() {
139
151
* @since 4.3
140
152
*/
141
153
public final void setTaskDecorator (TaskDecorator taskDecorator ) {
154
+ this .taskDecorator = taskDecorator ;
142
155
this .adaptedExecutor .setTaskDecorator (taskDecorator );
143
156
}
144
157
@@ -175,11 +188,15 @@ public <T> ListenableFuture<T> submitListenable(Callable<T> task) {
175
188
}
176
189
177
190
178
- private static TaskExecutorAdapter getAdaptedExecutor (Executor concurrentExecutor ) {
191
+ private TaskExecutorAdapter getAdaptedExecutor (Executor concurrentExecutor ) {
179
192
if (managedExecutorServiceClass != null && managedExecutorServiceClass .isInstance (concurrentExecutor )) {
180
193
return new ManagedTaskExecutorAdapter (concurrentExecutor );
181
194
}
182
- return new TaskExecutorAdapter (concurrentExecutor );
195
+ TaskExecutorAdapter adapter = new TaskExecutorAdapter (concurrentExecutor );
196
+ if (this .taskDecorator != null ) {
197
+ adapter .setTaskDecorator (this .taskDecorator );
198
+ }
199
+ return adapter ;
183
200
}
184
201
185
202
0 commit comments