users@jersey.java.net

Re: [Jersey] Using client apis on server (or calling a REST service from a REST service)

From: Tatu Saloranta <tsaloranta_at_gmail.com>
Date: Mon, 2 Nov 2009 20:10:45 -0800

On Mon, Nov 2, 2009 at 2:54 PM, Craig McClanahan <craigmcc_at_gmail.com> wrote:
> On Mon, Nov 2, 2009 at 2:08 PM, Andrew Ochsner <aochsner_at_cs.stanford.edu> wrote:
...
> A third choice would be to use a thread local variable containing
> Client instances, keyed by the current thread (Thread. in your
> resource classes (probably in an abstract base class to centralize the
> logic), and only create a Client instance the first time a particular
> request thread needs one.  The tricky part of this approach, however,
> is how to clean up these Client instances.  A ServletContextListener
...

I usually use a soft reference to wrap things that are recycled as an
optimization. This works quite well, and does not add noticeable
overhead for garbage collection (at least in amounts I have used it)
If additional cleanup is needed, it is possible to define reference
queues in which collected instances go to.

-+ Tatu +-