I have a service class that has a number of methods that make REST calls to a Spring REST service. Each of the methods is as follows:
public void getUser() { ClientConfig config = new DefaultClientConfig(); Client client = Client.create(config); WebResource service = client.resource(RESOURCE_URL);
This works fine, but I'm a little worried that every time the method is called, new instances of ClientConfig, Client, and WebResource are created. What would be the side effects associated with changing the above and creating ClientConfig, Client, and WebResource as class instance variables? those. change to this:
ClientConfig config = new DefaultClientConfig(); Client client = Client.create(config); WebResource service = client.resource(RESOURCE_URL); public void getUser() { // Get response as String String response = service.path("/addUser").accept(MediaType.TEXT_PLAIN) .get(String.class); return response; } public void getUserAccount() { // Get response as String String response = service.path("/getUserAccount").accept(MediaType.TEXT_PLAIN) .get(String.class); return response; }
Perhaps this is higher if several users call different methods at the same time? What is the best way to structure the above?
If the client methods in Jersey had close () methods, I could leave them as they are and just close the resources inside the methods.
ziggy source share