“ConnectionPoolTimeoutException” when iterating objects in S3

前端 未结 2 1499
别那么骄傲
别那么骄傲 2021-02-05 14:21

I\'ve been working for some time with aws java API with not so many problems. Currently I\'m using the library 1.5.2 version.

When I\'m iterating the objects inside a f

2条回答
  •  轮回少年
    2021-02-05 14:41

    I've found that S3Object opens a connection for each object. That are not liberated even if the object is garbage collected so it is needed to execute object.close(), in order to liberate the connection to the pool.

    So the corrected code would be:

     for (S3ObjectSummary objectSummary : current.getObjectSummaries()) {        
            S3Object object = s3.getObject(new GetObjectRequest(bucketName, objectSummary.getKey()));             
            System.out.println(object.getKey());
            object.close();
        }
    

提交回复
热议问题