8484import java .util .concurrent .CompletionException ;
8585import java .util .concurrent .ConcurrentHashMap ;
8686import java .util .concurrent .ExecutionException ;
87+ import java .util .concurrent .ExecutorService ;
8788import java .util .concurrent .TimeUnit ;
8889import java .util .logging .Logger ;
8990import java .util .stream .Collectors ;
@@ -136,6 +137,7 @@ public abstract class S3Base {
136137 protected String region ;
137138 protected Provider provider ;
138139 protected OkHttpClient httpClient ;
140+ private final ExecutorService executorService ;
139141
140142 protected S3Base (
141143 HttpUrl baseUrl ,
@@ -145,7 +147,8 @@ protected S3Base(
145147 boolean useVirtualStyle ,
146148 String region ,
147149 Provider provider ,
148- OkHttpClient httpClient ) {
150+ OkHttpClient httpClient ,
151+ ExecutorService executorService ) {
149152 this .baseUrl = baseUrl ;
150153 this .awsS3Prefix = awsS3Prefix ;
151154 this .awsDomainSuffix = awsDomainSuffix ;
@@ -154,6 +157,7 @@ protected S3Base(
154157 this .region = region ;
155158 this .provider = provider ;
156159 this .httpClient = httpClient ;
160+ this .executorService = executorService ;
157161 }
158162
159163 /** @deprecated This method is no longer supported. */
@@ -167,7 +171,8 @@ protected S3Base(
167171 boolean isDualStackHost ,
168172 boolean useVirtualStyle ,
169173 Provider provider ,
170- OkHttpClient httpClient ) {
174+ OkHttpClient httpClient ,
175+ ExecutorService executorService ) {
171176 this .baseUrl = baseUrl ;
172177 if (isAwsHost ) this .awsS3Prefix = "s3." ;
173178 if (isFipsHost ) this .awsS3Prefix = "s3-fips." ;
@@ -182,6 +187,7 @@ protected S3Base(
182187 this .region = region ;
183188 this .provider = provider ;
184189 this .httpClient = httpClient ;
190+ this .executorService = executorService ;
185191 }
186192
187193 protected S3Base (S3Base client ) {
@@ -193,6 +199,7 @@ protected S3Base(S3Base client) {
193199 this .region = client .region ;
194200 this .provider = client .provider ;
195201 this .httpClient = client .httpClient ;
202+ this .executorService = client .executorService ;
196203 }
197204
198205 /** Check whether argument is valid or not. */
@@ -1135,7 +1142,8 @@ protected CompletableFuture<Integer> calculatePartCountAsync(List<ComposeSource>
11351142 long [] objectSize = {0 };
11361143 int index = 0 ;
11371144
1138- CompletableFuture <Integer > completableFuture = CompletableFuture .supplyAsync (() -> 0 );
1145+ CompletableFuture <Integer > completableFuture =
1146+ CompletableFuture .supplyAsync (() -> 0 , executorService );
11391147 for (ComposeSource src : sources ) {
11401148 index ++;
11411149 final int i = index ;
@@ -2854,7 +2862,8 @@ private CompletableFuture<ObjectWriteResponse> putMultipartObjectAsync(
28542862 }
28552863 }
28562864 return response ;
2857- });
2865+ },
2866+ executorService );
28582867 }
28592868
28602869 /**
@@ -2900,7 +2909,8 @@ protected CompletableFuture<ObjectWriteResponse> putObjectAsync(
29002909 } catch (NoSuchAlgorithmException | IOException e ) {
29012910 throw new CompletionException (e );
29022911 }
2903- })
2912+ },
2913+ executorService )
29042914 .thenCompose (
29052915 partSource -> {
29062916 try {
0 commit comments