@@ -50,27 +50,27 @@ public class SimpleAsyncTaskExecutorBuilder {
5050
5151 private final String threadNamePrefix ;
5252
53- private final Integer concurrencyLimit ;
54-
5553 private final boolean rejectTasksWhenLimitReached ;
5654
55+ private final Integer concurrencyLimit ;
56+
5757 private final TaskDecorator taskDecorator ;
5858
5959 private final Set <SimpleAsyncTaskExecutorCustomizer > customizers ;
6060
6161 private final Duration taskTerminationTimeout ;
6262
6363 public SimpleAsyncTaskExecutorBuilder () {
64- this (null , null , null , false , null , null , null );
64+ this (null , null , false , null , null , null , null );
6565 }
6666
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 ,
6969 Set <SimpleAsyncTaskExecutorCustomizer > customizers , Duration taskTerminationTimeout ) {
7070 this .virtualThreads = virtualThreads ;
7171 this .threadNamePrefix = threadNamePrefix ;
72- this .concurrencyLimit = concurrencyLimit ;
7372 this .rejectTasksWhenLimitReached = rejectTasksWhenLimitReached ;
73+ this .concurrencyLimit = concurrencyLimit ;
7474 this .taskDecorator = taskDecorator ;
7575 this .customizers = customizers ;
7676 this .taskTerminationTimeout = taskTerminationTimeout ;
@@ -82,8 +82,9 @@ private SimpleAsyncTaskExecutorBuilder(Boolean virtualThreads, String threadName
8282 * @return a new builder instance
8383 */
8484 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 );
8788 }
8889
8990 /**
@@ -92,30 +93,35 @@ public SimpleAsyncTaskExecutorBuilder threadNamePrefix(String threadNamePrefix)
9293 * @return a new builder instance
9394 */
9495 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 );
9799 }
98100
99101 /**
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
102107 * @return a new builder instance
108+ * @since 3.5.0
103109 */
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 );
107114 }
108115
109116 /**
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
113119 * @return a new builder instance
114- * @since 3.5.0
115120 */
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 );
119125 }
120126
121127 /**
@@ -124,8 +130,9 @@ public SimpleAsyncTaskExecutorBuilder rejectTasksWhenLimitReached(boolean reject
124130 * @return a new builder instance
125131 */
126132 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 );
129136 }
130137
131138 /**
@@ -135,8 +142,9 @@ public SimpleAsyncTaskExecutorBuilder taskDecorator(TaskDecorator taskDecorator)
135142 * @since 3.2.1
136143 */
137144 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 );
140148 }
141149
142150 /**
@@ -165,8 +173,8 @@ public SimpleAsyncTaskExecutorBuilder customizers(SimpleAsyncTaskExecutorCustomi
165173 public SimpleAsyncTaskExecutorBuilder customizers (
166174 Iterable <? extends SimpleAsyncTaskExecutorCustomizer > customizers ) {
167175 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 ),
170178 this .taskTerminationTimeout );
171179 }
172180
@@ -194,9 +202,9 @@ public SimpleAsyncTaskExecutorBuilder additionalCustomizers(SimpleAsyncTaskExecu
194202 public SimpleAsyncTaskExecutorBuilder additionalCustomizers (
195203 Iterable <? extends SimpleAsyncTaskExecutorCustomizer > customizers ) {
196204 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 );
200208 }
201209
202210 /**
@@ -235,8 +243,8 @@ public <T extends SimpleAsyncTaskExecutor> T configure(T taskExecutor) {
235243 PropertyMapper map = PropertyMapper .get ().alwaysApplyingWhenNonNull ();
236244 map .from (this .virtualThreads ).to (taskExecutor ::setVirtualThreads );
237245 map .from (this .threadNamePrefix ).whenHasText ().to (taskExecutor ::setThreadNamePrefix );
238- map .from (this .concurrencyLimit ).to (taskExecutor ::setConcurrencyLimit );
239246 map .from (this .rejectTasksWhenLimitReached ).to (taskExecutor ::setRejectTasksWhenLimitReached );
247+ map .from (this .concurrencyLimit ).to (taskExecutor ::setConcurrencyLimit );
240248 map .from (this .taskDecorator ).to (taskExecutor ::setTaskDecorator );
241249 map .from (this .taskTerminationTimeout ).as (Duration ::toMillis ).to (taskExecutor ::setTaskTerminationTimeout );
242250 if (!CollectionUtils .isEmpty (this .customizers )) {
0 commit comments