Reputation: 99
I am using jersey-client (1.9) for calling api and everytime when i need to call a webservice i create a new client instance :
Client client = Client.create();
WebResource webResource = client.resource(url);
ClientResponse response = webResource
.queryParam(PARAM1, param1)
.queryParam(PARAM2, param2)
.type(MediaType.APPLICATION_JSON)
.get(ClientResponse.class);
the problem is after a period of time i get this exception :
com.sun.jersey.api.client.ClientHandlerException: java.net.SocketException: No buffer space available (maximum connections reached?): connect
If anyone could help me figure it out I would be very grateful .
Upvotes: 0
Views: 379
Reputation: 61
If you will provide additional details about the OS (windows/linux), more of the code or the type load your service is experiencing - all would help to provide a better answer.
A good guess though is that your OS is running out of sockets ports. Different OS's have different defaults and different ways of configuring how many sockets are available to establish TCP sockets.
though not exactly the same question, this one is similar can shed some light on your situation: java.net.SocketException: No buffer space available (maximum connections reached?): connect
There is also a write up about the same exception here: http://dbaktiar-on-java.blogspot.com/2010/03/hudson-shows-buffer-space-available.html
Upvotes: 1
Reputation: 7746
You have a resource leak. (Connections and InputStreams backing ClientResponses aren't being closed.) You can read a ClientResponse entity so that its associated resources are automatically closed by calling ClientResponse.readEntity()
, or you can manually close them via ClientResponse.close()
.
The following documentation may not exactly apply to the version of Jersey that you're using, but it's insightful:
Jersey Client API, Closing connections
Upvotes: 1