Facing problems with URLConnection under high load
Hi,
I have a piece of code that acts as a load balancer. Under high load scenario - 200+ different simulataneous users, it throws some errors.
Following is a snippet from that code -
URL url = new URL(site);
URLConnection urlconnection = url.openConnection();
urlconnection.setDoInput(true);
urlconnection.setDoOutput(true);
urlconnection.setUseCaches(false);
DataOutputStream dataoutputstream =
new DataOutputStream(urlconnection.getOutputStream());
dataoutputstream.writeBytes(posServiceRequest);
dataoutputstream.flush();
dataoutputstream.close();
InputStream inputstream = urlconnection.getInputStream();
httpservletresponse.setContentType(urlconnection.getContentType());
rewriteStreams(inputstream, httpservletresponse.getOutputStream());
inputstream.close();
-
Somewhere after around 200 odd users, this piece of code throws an error - "Error writing to server", a stacktrace print shows that the error occurs at the following line -
InputStream inputstream = urlconnection.getInputStream();
Any pointers would be appreciated.
Thanks,
-rahul

