Open andymc12 opened 5 years ago
For reference PR #7987 does now clean up JAXRSClientImpl resources on application stop so if a user does not close them on stop (probably usual), we do not leak any longer. The warning mentioned above though when a threshold is reached is still a good idea though.
RESTEasy does this - but it still might be nice to add for JAX-RS 2.0/2.1.
Per the Client javadocs: Clients are heavy-weight objects that manage the client-side communication infrastructure. Initialization as well as disposal of a
Client
instance may be a rather expensive operation. It is therefore advised to construct only a small number of Client instances in the application. Client instances must be properly closed before being disposed to avoid leaking resources.The best practice would be to create a small number of
Client
instances and re-use them to create multipleWebTarget
instances (which could also be re-used in most cases). Then close theClient
instance(s) when the app shuts down.In cases where the application creates multiple
Client
instances and does not close them, they will leak resources in thecom.ibm.ws.jaxrs20.client.JAXRSClientImpl
class. If left unchecked, this could lead to out of memory errors.The Liberty server should warn users when too many
Client
instances are in theJAXRSClientImpl
map. I suggest using 1000 as the default threshold, but to make that number configurable - the reason for that is that this map is used for active clients, and it is possible that a normal application may be running with over 1000 active clients (or that some applications may be in memory constrained environments and may need the warning much earlier).