Reputation: 55
I was just playing around with the SES package in AWS Java SDK for sending email. And I realized that there is this class [AmazonSimpleEmailServiceAsyncClient][1]
with a lot of
methods with Async
label.
I'm just curious when we have to use it, why, and how to use it. I've been looking around but haven't got good resources on that. Some conceptual explanation with snippets will be good.
Upvotes: 2
Views: 2479
Reputation: 64741
These asynchronous methods are available for most/all services within the AWS SDK for Java and usually not used when getting started due the slightly higher complexity attached to asynchronous programming, rather only when specific use cases suggest or demand it (accordingly this answer addresses your question from a conceptual point of view only, not specific to Amazon SES).
You can find a good explanation in Jason Fulghum's recent blog post Asynchronous Requests with the AWS SDK for Java:
When you call an operation with one of the standard, synchronous clients in the SDK, your code is blocked while the SDK sends your request, waits for the service to process it, and parses the response. This is an easy way to work with the SDK, but there are some situations where you just want to kick off the request, and let your code continue executing. The asynchronous clients in the SDK allow you to do exactly that. Kick off your requests, and check back later to see if they completed. [emphasis mine]
Jason also explains the two most common use cases where processing requests in the background makes sense:
Jason's post also links to his slightly more detailed earlier article about the subject matter, which describes the various synchronous and asynchronous approaches for making requests with the AWS SDK for Java and concludes with some additional information to help you use the asynchronous features successfully, see Asynchronous Programming with the AWS SDK for Java (the otherwise mostly identical code samples there also include exception handling).
Upvotes: 5