18
18
import java .util .ArrayList ;
19
19
import java .util .List ;
20
20
import java .util .concurrent .Executor ;
21
- import java .util .concurrent .Executors ;
21
+ import java .util .concurrent .LinkedBlockingQueue ;
22
+ import java .util .concurrent .ThreadPoolExecutor ;
23
+ import java .util .concurrent .TimeUnit ;
22
24
import java .util .function .Supplier ;
23
25
import lombok .Getter ;
24
26
@@ -142,7 +144,10 @@ public static class Builder {
142
144
private Supplier <BatchInputPreProcessor > batchInputPreProcessorSupplier =
143
145
NoOpBatchInputPreProcessor ::new ;
144
146
private GraphQLResponseCacheManager responseCacheManager ;
145
- private Executor asyncExecutor = Executors .newCachedThreadPool ();
147
+ private int asyncCorePoolSize = 10 ;
148
+ private int asyncMaxPoolSize = 200 ;
149
+ private Executor asyncExecutor ;
150
+ private AsyncTaskDecorator asyncTaskDecorator ;
146
151
147
152
private Builder (GraphQLInvocationInputFactory .Builder invocationInputFactoryBuilder ) {
148
153
this .invocationInputFactoryBuilder = invocationInputFactoryBuilder ;
@@ -203,6 +208,16 @@ public Builder with(Executor asyncExecutor) {
203
208
return this ;
204
209
}
205
210
211
+ public Builder asyncCorePoolSize (int asyncCorePoolSize ) {
212
+ this .asyncCorePoolSize = asyncCorePoolSize ;
213
+ return this ;
214
+ }
215
+
216
+ public Builder asyncMaxPoolSize (int asyncMaxPoolSize ) {
217
+ this .asyncMaxPoolSize = asyncMaxPoolSize ;
218
+ return this ;
219
+ }
220
+
206
221
public Builder with (ContextSetting contextSetting ) {
207
222
if (contextSetting != null ) {
208
223
this .contextSetting = contextSetting ;
@@ -229,6 +244,27 @@ public Builder with(GraphQLResponseCacheManager responseCache) {
229
244
return this ;
230
245
}
231
246
247
+ public Builder with (AsyncTaskDecorator asyncTaskDecorator ) {
248
+ this .asyncTaskDecorator = asyncTaskDecorator ;
249
+ return this ;
250
+ }
251
+
252
+ private Executor getAsyncExecutor () {
253
+ if (asyncExecutor != null ) {
254
+ return asyncExecutor ;
255
+ }
256
+ return new ThreadPoolExecutor (
257
+ asyncCorePoolSize ,
258
+ asyncMaxPoolSize ,
259
+ 60 ,
260
+ TimeUnit .SECONDS ,
261
+ new LinkedBlockingQueue <>(Integer .MAX_VALUE ));
262
+ }
263
+
264
+ private Executor getAsyncTaskExecutor () {
265
+ return new AsyncTaskExecutor (getAsyncExecutor (), asyncTaskDecorator );
266
+ }
267
+
232
268
public GraphQLConfiguration build () {
233
269
return new GraphQLConfiguration (
234
270
this .invocationInputFactory != null
@@ -243,7 +279,7 @@ public GraphQLConfiguration build() {
243
279
contextSetting ,
244
280
batchInputPreProcessorSupplier ,
245
281
responseCacheManager ,
246
- asyncExecutor );
282
+ getAsyncTaskExecutor () );
247
283
}
248
284
}
249
285
}
0 commit comments