@@ -192,12 +192,28 @@ public PutObjectResponse putObject(PutObjectRequest putObjectRequest, RequestBod
192
192
.secureRandom (_secureRandom )
193
193
.build ();
194
194
195
+ ExecutorService singleThreadExecutor = Executors .newSingleThreadExecutor ();
196
+
195
197
try {
196
- CompletableFuture <PutObjectResponse > futurePut = pipeline .putObject (putObjectRequest , AsyncRequestBody .fromInputStream (requestBody .contentStreamProvider ().newStream (), requestBody .optionalContentLength ().orElse (-1L ), Executors .newSingleThreadExecutor ()));
197
- return futurePut .join ();
198
+ CompletableFuture <PutObjectResponse > futurePut = pipeline .putObject (putObjectRequest ,
199
+ AsyncRequestBody .fromInputStream (
200
+ requestBody .contentStreamProvider ().newStream (),
201
+ requestBody .optionalContentLength ().orElse (-1L ),
202
+ singleThreadExecutor
203
+ )
204
+ );
205
+
206
+ PutObjectResponse response = futurePut .join ();
207
+
208
+ singleThreadExecutor .shutdown ();
209
+
210
+ return response ;
211
+
198
212
} catch (CompletionException completionException ) {
213
+ singleThreadExecutor .shutdownNow ();
199
214
throw new S3EncryptionClientException (completionException .getMessage (), completionException .getCause ());
200
215
} catch (Exception exception ) {
216
+ singleThreadExecutor .shutdownNow ();
201
217
throw new S3EncryptionClientException (exception .getMessage (), exception );
202
218
}
203
219
@@ -279,7 +295,6 @@ private CompleteMultipartUploadResponse multipartPutObject(PutObjectRequest requ
279
295
}
280
296
281
297
ExecutorService es = multipartConfiguration .executorService ();
282
- final boolean defaultExecutorService = es == null ;
283
298
if (es == null ) {
284
299
throw new S3EncryptionClientException ("ExecutorService should not be null, Please initialize during MultipartConfiguration" );
285
300
}
@@ -315,8 +330,8 @@ private CompleteMultipartUploadResponse multipartPutObject(PutObjectRequest requ
315
330
} catch (IOException | InterruptedException | ExecutionException | RuntimeException | Error ex ) {
316
331
throw onAbort (observer , ex );
317
332
} finally {
318
- if (defaultExecutorService ) {
319
- // shut down the locally created thread pool
333
+ if (multipartConfiguration . usingDefaultExecutorService () ) {
334
+ // shut down the thread pool if it was created by the encryption client
320
335
es .shutdownNow ();
321
336
}
322
337
// delete left-over temp files
0 commit comments