title: Will Transfer Manager Instance get shut down if Progress Listener is added
body: <p>I'm using transfer manager to upload files to an S3 bucket. I wanted the upload process to be asynchronous, hence, wanted to avoid the <code>waitForCompletion()</code> method. But, I cannot  use <code>shutDownNow()</code> without using <code>waitForCompletion()</code>. I was reading some articles that said using a progress listener to get event update will close the transfer manager instance once event is completed. Now, will this be a custom progress listener or can I use a general one like this:</p>
  <pre><code>ProgressListener progressListener = progressEvent -&gt; System.out.println(
    &quot;Transferred bytes: &quot; + progressEvent.getBytesTransferred());
  PutObjectRequest request = new PutObjectRequest(
    bucketName, keyName, file);
  request.setGeneralProgressListener(progressListener);
  Upload upload = tm.upload(request);
  </code></pre>
  <p>code source: <a href="https://www.baeldung.com/aws-s3-multipart-upload" rel="nofollow noreferrer">https://www.baeldung.com/aws-s3-multipart-upload</a></p>
  <p><strong>Update:</strong></p>
  <p>Implemented some code where in the transfer manager instance is shut down after file is uploaded but without having to use <code>waitForCompletion()</code>. Used a custom ProgressListener and once Event is completed, called <code>shutDownNow(false)</code> on the transfer manager instance.</p>
  <pre><code>public void uploadPermissibleFile(MultipartFile file, String bucket, String filePath){
          TransferManager tm = TransferManagerBuilder.standard()
                  .withS3Client(bos3Config.getS3Client())
                  .withMultipartUploadThreshold((long) (5 * 1024 * 1025))
                  .build();
          try {
              ObjectMetadata metadata = new ObjectMetadata();
              log.info(&quot;Uploading file with length: {}&quot;, file.getSize());
              metadata.setContentLength(file.getSize());
              PutObjectRequest putObjectRequest = new PutObjectRequest(bucket, filePath, file.getInputStream(), metadata);
              ProgressListener progressListener = progressEvent -&gt; {
                  if(progressEvent.getEventType() == ProgressEventType.TRANSFER_STARTED_EVENT){
                      log.info(&quot;Progress Event =&gt; Started Permissible File upload process&quot;);
                  }
                  if(progressEvent.getEventType() == ProgressEventType.TRANSFER_COMPLETED_EVENT){
                      log.info(&quot;Progress Event =&gt; Permissible File uploading process completed&quot;);
                      tm.shutdownNow(false);
                      log.info(&quot;transfer manager shutdown complete&quot;);
                  }
                  if(progressEvent.getEventType() == ProgressEventType.TRANSFER_FAILED_EVENT){
                      log.info(&quot;Progress Event =&gt; Permissible File uploading process failed&quot;);
                      tm.shutdownNow(false);
                      log.info(&quot;transfer manager shutdown complete&quot;);
                  }
              };
              
              Upload upload = tm.upload(putObjectRequest);
              upload.addProgressListener(progressListener);
              
          }catch(AmazonClientException e){
              log.error(&quot;Error while uploading permissible users file to s3 bucket: {}&quot;, e.getMessage());
              tm.shutdownNow(false);
              throw e;
          }catch (IOException e) {
              log.error(&quot;Error while uploading permissible users file to s3 bucket: {}&quot;, e.getMessage());
              tm.shutdownNow(false);
              throw new RuntimeException(e);
          }
  
      }
  </code></pre>
  <p>The file upload is working as expected, in an asynchronous way. Would be really helpful if it can be validated. Any inputs on improving the code is much appreciated!!</p>