Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it safe to declare an AWS Java SDK client object as static for concurrent use?

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.

like image 751
RTF Avatar asked Oct 15 '14 11:10

RTF


People also ask

Are AWS SDK clients thread safe?

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.

Is Java s3 client thread safe?

All the clients in the AWS SDK for Java are thread safe and you should to reuse client objects.

Is AWS SDK secure?

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 .

Can you interface with AWS using Java SDK?

Develop and deploy applications with the AWS SDK for Java. The SDK makes it easy to call AWS services using idiomatic Java APIs.


1 Answers

All the clients in the AWS SDK for Java are thread safe and you should to reuse client objects.

like image 122
Julio Faerman Avatar answered Oct 06 '22 02:10

Julio Faerman