1818import java .util .ArrayList ;
1919import java .util .List ;
2020import 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 ;
2224import java .util .function .Supplier ;
2325import lombok .Getter ;
2426
@@ -142,7 +144,10 @@ public static class Builder {
142144 private Supplier <BatchInputPreProcessor > batchInputPreProcessorSupplier =
143145 NoOpBatchInputPreProcessor ::new ;
144146 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 ;
146151
147152 private Builder (GraphQLInvocationInputFactory .Builder invocationInputFactoryBuilder ) {
148153 this .invocationInputFactoryBuilder = invocationInputFactoryBuilder ;
@@ -203,6 +208,16 @@ public Builder with(Executor asyncExecutor) {
203208 return this ;
204209 }
205210
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+
206221 public Builder with (ContextSetting contextSetting ) {
207222 if (contextSetting != null ) {
208223 this .contextSetting = contextSetting ;
@@ -229,6 +244,27 @@ public Builder with(GraphQLResponseCacheManager responseCache) {
229244 return this ;
230245 }
231246
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+
232268 public GraphQLConfiguration build () {
233269 return new GraphQLConfiguration (
234270 this .invocationInputFactory != null
@@ -243,7 +279,7 @@ public GraphQLConfiguration build() {
243279 contextSetting ,
244280 batchInputPreProcessorSupplier ,
245281 responseCacheManager ,
246- asyncExecutor );
282+ getAsyncTaskExecutor () );
247283 }
248284 }
249285}
0 commit comments