Home > Software engineering >  How to use the Amazon S3 Java API to perform getObject using an asynchronous call
How to use the Amazon S3 Java API to perform getObject using an asynchronous call

Time:09-27

I need to download a lot of files from S3 so I wrapped many calls to s3Client.getObject(request, destination) with futures, but there's no mention of it being blocking so I'm afraid I might run into a race condition where all the download calls were made but the files weren't really downloaded yet.

Is it safe to assume this api is blocking since there's no mention of it being async?

To clarify, by blocking I mean that the flow won't continue after the s3Client.getObject(request, destination) line until the download is finished.

enter image description here

CodePudding user response:

Looking at the code on Github, it is indeed blocking the call (invoke).

CodePudding user response:

TO use the latest non-blocking code (AWS SDK for Java V2), refer to this Github example. This shows how to use getObject using the asynchronous client.

https://github.com/awsdocs/aws-doc-sdk-examples/blob/master/javav2/example_code/s3/src/main/java/com/example/s3/S3AsyncStreamOps.java

  • Related