Is it safe to use the same client object for multiple requests concurrently with the AWS Java SDK. For example, if I have a web server handling multiple requests concurrently and one or more of the requests need access to DynamoDB, is it safe have a static client object for reads and writes with static accessor methods e.g.
public class DynamoDBManager {
private static AmazonDynamoDBClient client = new AmazonDynamoDBClient(CREDENTIALS);
public static void doRead(String hashKey) {
// use the client to read
}
public static void doWrite(MyData data) {
// use the client to write
}
}
...or should I drop the static modifiers on the methods and the client object so that every time a web server request needs access to the database it must instantiate the manager class to get it's own version of the client.
Will there be any concurrency issues or conflicts if the client object is static? I'm using DynamoDB here as an example, but I'm just as interested in the same scenario with an S3 client.
Client Lifecycle Service clients in the SDK are thread-safe and, for best performance, you should treat them as long-lived objects. Each client has its own connection pool resource.
All the clients in the AWS SDK for Java are thread safe and you should to reuse client objects.
Our security responsibility is the highest priority at AWS, and the effectiveness of our security is regularly tested and verified by third-party auditors as part of the AWS Compliance Programs .
Develop and deploy applications with the AWS SDK for Java. The SDK makes it easy to call AWS services using idiomatic Java APIs.
All the clients in the AWS SDK for Java are thread safe and you should to reuse client objects.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With