I ever used the code
public static AmazonS3Client s3 = null;
...
BasicAWSCredentials c = new BasicAWSCredentials("absadgwslkjlsdjgflwa");
s3 = new AmazonS3Client(c);
Only one instance s3 is created while dozens of threads will upload images by s3.putObject(). In the dump info, I could see that one thread would lock the only instance s3 while the others were waiting.
So I think maybe it will be faster if I use the code below:
BasicAWSCredentials c = new BasicAWSCredentials("absadgwslkjlsdjgflwa");
for(int i = 0; i < 10; i++)
amazonS3[i] = new AmazonS3Client(c);
Everytime the system will get a random s3 instance and then upload the image.
private static AmazonS3 getS3(){
int i = (int)(Math.random() * 10);
return amazonS3[i];
}
But it seems that the system slow down. Why that happened?
Maybe the only instance s3 has already used connection pool? I am confused.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…