I'm uploading files to s3 using the s3 AWS client in my spring application, but sometimes I'm getting the error,
com.amazonaws.SdkClientException: Unable to execute HTTP request: Timeout waiting for connection from pool
com.amazonaws.SdkClientException: Unable to execute HTTP request: Timeout waiting for connection from pool
Caused by: org.apache.http.conn.ConnectionPoolTimeoutException: Timeout waiting for connection from pool
So as a solution to this I used the following approach and it worked for now.
@Bean
public AmazonS3 s3Client() {
return AmazonS3ClientBuilder
.standard()
.withClientConfiguration(new ClientConfiguration()
.withMaxConnections(100)
.withConnectionTimeout(100)
.withMaxErrorRetry(5))
.build();
}
public String uploadFile() {
// upload code
}
I have created this as a Spring Bean. But I am using this in a multithreading environment. So there will many concurrent requests at the same time. I see that AmazonS3ClientBuilder
is annotated with @NotThreadSafe
. So I need to know is it okay to use this as a bean in multithreading or else shall I use the above block of code inside the same uploadFile
method? Can anyone explain me the best way? Thank you