I have written a service which is used to register some data. That service can be called thousands of times. The parameters are passed via the URL itself. The client part of it looks something like this:
private String getNodeInfoFromGPSForSpecificSubscriber( int subscriberId ) throws Exception {
String requestURLToNode = "http://" + GPSConstants.GPS_IP + ":" + GPSConstants.PORT_NUMBER + APIs.FetchASpeecificNodeAPI.FETCH_A_SPECIFIC_NODE + "?" + APIs.FetchASpeecificNodeAPI.SUBSCRIBER_ID + "=" + subscriberId;
URL url = new URL( requestURLToNode );
HttpURLConnection conn = ( HttpURLConnection ) url.openConnection();
conn.setRequestMethod( "GET" );
conn.setRequestProperty( "Accept", "application/xml" );
conn.setDoOutput( true );
InputStream inputStream = conn.getInputStream();
BufferedReader in = new BufferedReader( new InputStreamReader( inputStream ) );
String responseAsString = in.readLine();
in.close();
conn.disconnect();
System.out.println( ++i );
return responseAsString;
}
But here, every time a connection gets opened, and thus speed am getting is only around 1 record per second. I know I need not open a connection everytime, but not able to figure out how. Kindly help.
14/04/11 22:47:25 ERROR client.RegisterNewCell: java.net.SocketException: No buffer space available (maximum connections reached?): connect
after some runs. – Enwreathein.close()
in the above code, it runs faster but then stops throwing that exception. – Enwreathein.close()
andconn.disconnect()
are only called in "happy-path". Maybe you need more robust exception handling!? Try a tested library like DavidWebb or one of the listed alternatives. – Remingtonin.close()
the speeds am getting is only a request per second. – Enwreathe