Hi Oleg, Thanks for your response.
On Fri, Nov 16, 2012 at 10:59 AM, Oleg Kalnichevski <[email protected]>wrote: > On Thu, 2012-11-15 at 16:42 -0500, Sachin Nikumbh wrote: > > Hi, > > > > I have successfully used the HTTP Async client. It's working great for > the > > most part. In my application I am creating multiple instances > > of DefaultHttpAsyncClient. However, I > > get java.nio.channels.AsynchronousCloseException once in a while with > > following stack: > > > > > **************************************************************************************** > > ..............Nov 15, 2012 4:23:41 PM > > org.apache.http.impl.nio.client.LoggingAsyncRequestExecutor exception > > SEVERE: http-outgoing-3 [CLOSED] HTTP protocol exception: null > > java.nio.channels.AsynchronousCloseException > > at > > > java.nio.channels.spi.AbstractInterruptibleChannel.end(AbstractInterruptibleChannel.java:185) > > at sun.nio.ch.SocketChannelImpl.read(SocketChannelImpl.java:270) > > at > > > org.apache.http.impl.nio.reactor.SessionInputBufferImpl.fill(SessionInputBufferImpl.java:97) > > at > > > org.apache.http.impl.nio.codecs.AbstractMessageParser.fillBuffer(AbstractMessageParser.java:115) > > at > > > org.apache.http.impl.nio.DefaultNHttpClientConnection.consumeInput(DefaultNHttpClientConnection.java:167) > > at > > > org.apache.http.impl.nio.DefaultHttpClientIODispatch.onInputReady(DefaultHttpClientIODispatch.java:125) > > at > > > org.apache.http.impl.nio.DefaultHttpClientIODispatch.onInputReady(DefaultHttpClientIODispatch.java:49) > > at > > > org.apache.http.impl.nio.reactor.AbstractIODispatch.inputReady(AbstractIODispatch.java:112) > > at > > > org.apache.http.impl.nio.reactor.BaseIOReactor.readable(BaseIOReactor.java:160) > > at > > > org.apache.http.impl.nio.reactor.AbstractIOReactor.processEvent(AbstractIOReactor.java:342) > > at > > > org.apache.http.impl.nio.reactor.AbstractIOReactor.processEvents(AbstractIOReactor.java:320) > > at > > > org.apache.http.impl.nio.reactor.AbstractIOReactor.execute(AbstractIOReactor.java:280) > > at > > > org.apache.http.impl.nio.reactor.BaseIOReactor.execute(BaseIOReactor.java:106) > > at > > > org.apache.http.impl.nio.reactor.AbstractMultiworkerIOReactor$Worker.run(AbstractMultiworkerIOReactor.java:604) > > at java.lang.Thread.run(Thread.java:662) > > > **************************************************************************************** > > > > Following is the snippet of how I am using an instance of > > DefaultHttpAsyncClient in my code: > > > > > **************************************************************************************** > > HttpAsyncClient httpClientAsync = new DefaultHttpAsyncClient(); > > httpClientAsync.start(); > > final HttpPost postReq = new HttpPost(mpsUrl); > > postReq.setEntity(new ByteArrayEntity(mlParams.toByteArray())); > > final Future<HttpResponse> future = httpClientAsync.execute(postReq, > null); > > final HttpResponse response = future.get(); > > // DO SOMETHING WITH REPOSNSE > > httpClientAsync.shutdown(); > > > **************************************************************************************** > > > > Can the shutdown() call on one instance affect other instances > > of DefaultHttpAsyncClient? Is there any global state that multiple > > instances of DefaultHttpAsyncClient share that may be causing this > problem? > > > > No, it cannot, as long those instances do not share a common pool of > connections. > Under what circumstances can I get into the situation where multiple instances of DefaultHttpAsyncClient are sharing a common pool of connections? If I am only using default DefaultHttpAsyncClient constructor to create multiple instances, can I get myself into this situation without realizing? The stack trace is making me believe so. > I would recommend using only one instance of DefaultHttpAsyncClient per > distinct HTTP service. Creating a new DefaultHttpAsyncClient instance > for each and every request is enormously wasteful and inefficient. > I ended up with multiple DefaultHttpAsyncClient instances in the tests that I was writing. I completely agree that creating multiple DefaultHttpAsyncClient instances is wasteful and I do not intend to do it in the final code. Sachin
