abdera-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From James M Snell <jasn...@gmail.com>
Subject Re: Thread safety and resource usage of AbderaClient
Date Thu, 24 May 2012 18:35:18 GMT
On Thu, May 24, 2012 at 3:36 AM, Morten Bendiksen <MBendiksen@vizrt.com> wrote:
> Hi,
>
> I am using Abdera in a project where different threads use the AbderaClient to read and
post ducuments from/to a server. I am wondering what are the recommended way to do this safely
and without consuming too many resources. Can I safely share one instance of AberaClient between
multiple threads? Should I always call the ClientResponse.release() method after I'm done
with a response?
>

Instances of AbderaClient are generally threadsafe as long as you're
careful not to be changing configuration properties within individual
threads. It does use the multithreaded connection manager under the
covers. The Response objects, however, are not threadsafe and must
only ever be used by a single thread; and yes, you need to call
release() when you're done with the response. Note, however, that
because of the lazy parsing model, you need to ensure that the stream
is completely parsed or buffered before calling release or you will
see IOExceptions.

> When I blindly followed the Getting started guide, I quickly ran into problems of performance
and even ran out of connections after a while. Now I call the .teardown() method when I'm
no longer using the AbderaClient, and things improved. I could not find any documentation
about this though, so I am therefore asking here, since I really want to ensure I'm doing
things the right way, so I don't bump into other problems later.

Yes, this particular part of the code was limited by the design of the
apache http client 3.x and definitely could have been better
documented. Always call teardown and release to free up the resources
as the http client definitely likes to hold on to things.

>
> Best regards,
> Morten Bendiksen

Mime
View raw message