java - "ConnectionPoolTimeoutException" when iterating objects in S3 -
i've been working time aws java api not many problems. i'm using library 1.5.2 version.
when i'm iterating objects inside folder following code:
amazons3 s3 = new amazons3client(new propertiescredentials(myclass.class.getresourceasstream("awscredentials.properties"))); string s3key = "folder1/folder2"; string bucketname = constantes.s3_bucket; string key = s3key +"/input_chopped/"; objectlisting current = s3.listobjects(new listobjectsrequest() .withbucketname(bucketname) .withprefix(key)); boolean siguiente = true; while (siguiente) { siguiente &= current.istruncated(); contador += current.getobjectsummaries().size(); (s3objectsummary objectsummary : current.getobjectsummaries()) { s3object object = s3.getobject(new getobjectrequest(bucketname, objectsummary.getkey())); system.out.println(object.getkey()); } current=s3.listnextbatchofobjects(current); }
gist: link: https://gist.github.com/fgblanch/6038699 i'm getting following exception:
info (amazonhttpclient.java:358) - unable execute http request: timeout waiting connection pool org.apache.http.conn.connectionpooltimeoutexception: timeout waiting connection pool @ org.apache.http.impl.conn.poolingclientconnectionmanager.leaseconnection(poolingclientconnectionmanager.java:232) @ org.apache.http.impl.conn.poolingclientconnectionmanager$1.getconnection(poolingclientconnectionmanager.java:199) @ org.apache.http.impl.client.defaultrequestdirector.execute(defaultrequestdirector.java:456) @ org.apache.http.impl.client.abstracthttpclient.execute(abstracthttpclient.java:906) @ org.apache.http.impl.client.abstracthttpclient.execute(abstracthttpclient.java:805) @ org.apache.http.impl.client.abstracthttpclient.execute(abstracthttpclient.java:784) @ com.amazonaws.http.amazonhttpclient.executehelper(amazonhttpclient.java:315) @ com.amazonaws.http.amazonhttpclient.execute(amazonhttpclient.java:199) @ com.amazonaws.services.s3.amazons3client.invoke(amazons3client.java:2994) @ com.amazonaws.services.s3.amazons3client.getobject(amazons3client.java:918) @ com.madiva.segmentacion.tests.listas3.main(listas3.java:177) @ sun.reflect.nativemethodaccessorimpl.invoke0(native method) @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:39) @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:25) @ java.lang.reflect.method.invoke(method.java:597) @ com.intellij.rt.execution.application.appmain.main(appmain.java:120) caught amazonclientexception, means client encountered serious internal problem while trying communicate s3, such not being able access network. error message: unable execute http request: timeout waiting connection pool
any idea how avoid error. happens in folders number of object , in case there 463 files inside. thanks
i've found s3object opens connection each object. not liberated if object garbage collected needed execute object.close(), in order liberate connection pool.
so corrected code be:
(s3objectsummary objectsummary : current.getobjectsummaries()) { s3object object = s3.getobject(new getobjectrequest(bucketname, objectsummary.getkey())); system.out.println(object.getkey()); object.close(); }
Comments
Post a Comment