users@jersey.java.net

[Jersey] Jersey Client 2.4.1 - best practices

From: Trudeau, Simon <Simon_Trudeau_at_silanis.com>
Date: Wed, 18 Dec 2013 11:55:12 -0500

I'm new to Jersey and would like to know what are the best practices
when making use of Jersey Client.

 

In our application, we make use of Jersey to connect to REST services
with many URLs of type: /foo/bar/{random id}/stuff

 

This leads to the creation of many WebTarget objects, which is expected.
We did try to have one instance of JerseyClient for the whole
application but ended up having memory leaks. The JerseyClient keeps a
copy of the Config for all WebTarget objects created. (Note that we
would have expected the WebTarget object to get fully garbage
collected...). To resolve the leak we ended up having to create one
JerseyClient for each WebTarget.

 

- What do you recommend in terms of best practices when
creating JerseyClient and WebTarget objects?

- Do we need to explicitly call close() on JerseyClient to make
sure it releases all resources (SSL context, for example) or can we rely
on the garbage collector.

- Anything else you would recommend? :.)

 

Thanks,

 

 

Simon