@@ -50,27 +50,27 @@ public class SimpleAsyncTaskExecutorBuilder {
50
50
51
51
private final String threadNamePrefix ;
52
52
53
- private final Integer concurrencyLimit ;
54
-
55
53
private final boolean rejectTasksWhenLimitReached ;
56
54
55
+ private final Integer concurrencyLimit ;
56
+
57
57
private final TaskDecorator taskDecorator ;
58
58
59
59
private final Set <SimpleAsyncTaskExecutorCustomizer > customizers ;
60
60
61
61
private final Duration taskTerminationTimeout ;
62
62
63
63
public SimpleAsyncTaskExecutorBuilder () {
64
- this (null , null , null , false , null , null , null );
64
+ this (null , null , false , null , null , null , null );
65
65
}
66
66
67
- private SimpleAsyncTaskExecutorBuilder (Boolean virtualThreads , String threadNamePrefix , Integer concurrencyLimit ,
68
- boolean rejectTasksWhenLimitReached , TaskDecorator taskDecorator ,
67
+ private SimpleAsyncTaskExecutorBuilder (Boolean virtualThreads , String threadNamePrefix ,
68
+ boolean rejectTasksWhenLimitReached , Integer concurrencyLimit , TaskDecorator taskDecorator ,
69
69
Set <SimpleAsyncTaskExecutorCustomizer > customizers , Duration taskTerminationTimeout ) {
70
70
this .virtualThreads = virtualThreads ;
71
71
this .threadNamePrefix = threadNamePrefix ;
72
- this .concurrencyLimit = concurrencyLimit ;
73
72
this .rejectTasksWhenLimitReached = rejectTasksWhenLimitReached ;
73
+ this .concurrencyLimit = concurrencyLimit ;
74
74
this .taskDecorator = taskDecorator ;
75
75
this .customizers = customizers ;
76
76
this .taskTerminationTimeout = taskTerminationTimeout ;
@@ -82,8 +82,9 @@ private SimpleAsyncTaskExecutorBuilder(Boolean virtualThreads, String threadName
82
82
* @return a new builder instance
83
83
*/
84
84
public SimpleAsyncTaskExecutorBuilder threadNamePrefix (String threadNamePrefix ) {
85
- return new SimpleAsyncTaskExecutorBuilder (this .virtualThreads , threadNamePrefix , this .concurrencyLimit ,
86
- this .rejectTasksWhenLimitReached , this .taskDecorator , this .customizers , this .taskTerminationTimeout );
85
+ return new SimpleAsyncTaskExecutorBuilder (this .virtualThreads , threadNamePrefix ,
86
+ this .rejectTasksWhenLimitReached , this .concurrencyLimit , this .taskDecorator , this .customizers ,
87
+ this .taskTerminationTimeout );
87
88
}
88
89
89
90
/**
@@ -92,30 +93,35 @@ public SimpleAsyncTaskExecutorBuilder threadNamePrefix(String threadNamePrefix)
92
93
* @return a new builder instance
93
94
*/
94
95
public SimpleAsyncTaskExecutorBuilder virtualThreads (Boolean virtualThreads ) {
95
- return new SimpleAsyncTaskExecutorBuilder (virtualThreads , this .threadNamePrefix , this .concurrencyLimit ,
96
- this .rejectTasksWhenLimitReached , this .taskDecorator , this .customizers , this .taskTerminationTimeout );
96
+ return new SimpleAsyncTaskExecutorBuilder (virtualThreads , this .threadNamePrefix ,
97
+ this .rejectTasksWhenLimitReached , this .concurrencyLimit , this .taskDecorator , this .customizers ,
98
+ this .taskTerminationTimeout );
97
99
}
98
100
99
101
/**
100
- * Set the concurrency limit.
101
- * @param concurrencyLimit the concurrency limit
102
+ * Set whether to reject tasks when the concurrency limit has been reached. By default
103
+ * {@code false} to block the caller until the submission can be accepted. Switch to
104
+ * {@code true} for immediate rejection instead.
105
+ * @param rejectTasksWhenLimitReached whether to reject tasks when the concurrency
106
+ * limit has been reached
102
107
* @return a new builder instance
108
+ * @since 3.5.0
103
109
*/
104
- public SimpleAsyncTaskExecutorBuilder concurrencyLimit (Integer concurrencyLimit ) {
105
- return new SimpleAsyncTaskExecutorBuilder (this .virtualThreads , this .threadNamePrefix , concurrencyLimit ,
106
- this .rejectTasksWhenLimitReached , this .taskDecorator , this .customizers , this .taskTerminationTimeout );
110
+ public SimpleAsyncTaskExecutorBuilder rejectTasksWhenLimitReached (boolean rejectTasksWhenLimitReached ) {
111
+ return new SimpleAsyncTaskExecutorBuilder (this .virtualThreads , this .threadNamePrefix ,
112
+ rejectTasksWhenLimitReached , this .concurrencyLimit , this .taskDecorator , this .customizers ,
113
+ this .taskTerminationTimeout );
107
114
}
108
115
109
116
/**
110
- * Specify whether to reject tasks when the concurrency limit has been reached.
111
- * @param rejectTasksWhenLimitReached whether to reject tasks when the concurrency
112
- * limit has been reached
117
+ * Set the concurrency limit.
118
+ * @param concurrencyLimit the concurrency limit
113
119
* @return a new builder instance
114
- * @since 3.5.0
115
120
*/
116
- public SimpleAsyncTaskExecutorBuilder rejectTasksWhenLimitReached (boolean rejectTasksWhenLimitReached ) {
117
- return new SimpleAsyncTaskExecutorBuilder (this .virtualThreads , this .threadNamePrefix , this .concurrencyLimit ,
118
- rejectTasksWhenLimitReached , this .taskDecorator , this .customizers , this .taskTerminationTimeout );
121
+ public SimpleAsyncTaskExecutorBuilder concurrencyLimit (Integer concurrencyLimit ) {
122
+ return new SimpleAsyncTaskExecutorBuilder (this .virtualThreads , this .threadNamePrefix ,
123
+ this .rejectTasksWhenLimitReached , concurrencyLimit , this .taskDecorator , this .customizers ,
124
+ this .taskTerminationTimeout );
119
125
}
120
126
121
127
/**
@@ -124,8 +130,9 @@ public SimpleAsyncTaskExecutorBuilder rejectTasksWhenLimitReached(boolean reject
124
130
* @return a new builder instance
125
131
*/
126
132
public SimpleAsyncTaskExecutorBuilder taskDecorator (TaskDecorator taskDecorator ) {
127
- return new SimpleAsyncTaskExecutorBuilder (this .virtualThreads , this .threadNamePrefix , this .concurrencyLimit ,
128
- this .rejectTasksWhenLimitReached , taskDecorator , this .customizers , this .taskTerminationTimeout );
133
+ return new SimpleAsyncTaskExecutorBuilder (this .virtualThreads , this .threadNamePrefix ,
134
+ this .rejectTasksWhenLimitReached , this .concurrencyLimit , taskDecorator , this .customizers ,
135
+ this .taskTerminationTimeout );
129
136
}
130
137
131
138
/**
@@ -135,8 +142,9 @@ public SimpleAsyncTaskExecutorBuilder taskDecorator(TaskDecorator taskDecorator)
135
142
* @since 3.2.1
136
143
*/
137
144
public SimpleAsyncTaskExecutorBuilder taskTerminationTimeout (Duration taskTerminationTimeout ) {
138
- return new SimpleAsyncTaskExecutorBuilder (this .virtualThreads , this .threadNamePrefix , this .concurrencyLimit ,
139
- this .rejectTasksWhenLimitReached , this .taskDecorator , this .customizers , taskTerminationTimeout );
145
+ return new SimpleAsyncTaskExecutorBuilder (this .virtualThreads , this .threadNamePrefix ,
146
+ this .rejectTasksWhenLimitReached , this .concurrencyLimit , this .taskDecorator , this .customizers ,
147
+ taskTerminationTimeout );
140
148
}
141
149
142
150
/**
@@ -165,8 +173,8 @@ public SimpleAsyncTaskExecutorBuilder customizers(SimpleAsyncTaskExecutorCustomi
165
173
public SimpleAsyncTaskExecutorBuilder customizers (
166
174
Iterable <? extends SimpleAsyncTaskExecutorCustomizer > customizers ) {
167
175
Assert .notNull (customizers , "'customizers' must not be null" );
168
- return new SimpleAsyncTaskExecutorBuilder (this .virtualThreads , this .threadNamePrefix , this . concurrencyLimit ,
169
- this .rejectTasksWhenLimitReached , this .taskDecorator , append (null , customizers ),
176
+ return new SimpleAsyncTaskExecutorBuilder (this .virtualThreads , this .threadNamePrefix ,
177
+ this .rejectTasksWhenLimitReached , this .concurrencyLimit , this . taskDecorator , append (null , customizers ),
170
178
this .taskTerminationTimeout );
171
179
}
172
180
@@ -194,9 +202,9 @@ public SimpleAsyncTaskExecutorBuilder additionalCustomizers(SimpleAsyncTaskExecu
194
202
public SimpleAsyncTaskExecutorBuilder additionalCustomizers (
195
203
Iterable <? extends SimpleAsyncTaskExecutorCustomizer > customizers ) {
196
204
Assert .notNull (customizers , "'customizers' must not be null" );
197
- return new SimpleAsyncTaskExecutorBuilder (this .virtualThreads , this .threadNamePrefix , this . concurrencyLimit ,
198
- this .rejectTasksWhenLimitReached , this .taskDecorator , append ( this .customizers , customizers ) ,
199
- this .taskTerminationTimeout );
205
+ return new SimpleAsyncTaskExecutorBuilder (this .virtualThreads , this .threadNamePrefix ,
206
+ this .rejectTasksWhenLimitReached , this .concurrencyLimit , this .taskDecorator ,
207
+ append ( this . customizers , customizers ), this .taskTerminationTimeout );
200
208
}
201
209
202
210
/**
@@ -235,8 +243,8 @@ public <T extends SimpleAsyncTaskExecutor> T configure(T taskExecutor) {
235
243
PropertyMapper map = PropertyMapper .get ().alwaysApplyingWhenNonNull ();
236
244
map .from (this .virtualThreads ).to (taskExecutor ::setVirtualThreads );
237
245
map .from (this .threadNamePrefix ).whenHasText ().to (taskExecutor ::setThreadNamePrefix );
238
- map .from (this .concurrencyLimit ).to (taskExecutor ::setConcurrencyLimit );
239
246
map .from (this .rejectTasksWhenLimitReached ).to (taskExecutor ::setRejectTasksWhenLimitReached );
247
+ map .from (this .concurrencyLimit ).to (taskExecutor ::setConcurrencyLimit );
240
248
map .from (this .taskDecorator ).to (taskExecutor ::setTaskDecorator );
241
249
map .from (this .taskTerminationTimeout ).as (Duration ::toMillis ).to (taskExecutor ::setTaskTerminationTimeout );
242
250
if (!CollectionUtils .isEmpty (this .customizers )) {
0 commit comments