I modified the sample code available here for Client and Server My client :
public class Client {
public static void main(String[] args) {
int n=10000;
I believe the ConnectException
you are getting with 500 threads is not coming from SocketTest.connect()
. It could be coming from any of the other IO methods.
For a quick fix (and to convince yourself), you can explicitly catch ConnectException
in your main try-catch
block like this:
try {
// connect, write, and read ...
} catch (ConnectException ce) { // <-- catch the more specific Exception first
System.out.println("You caught a ConnectException.");
} catch (IOException e1) { // <-- you originally only caught this
// TODO Auto-generated catch block
e1.printStackTrace();
} finally {
As to why this is happening, I can tell you that I am currently ramping up to hundreds of threads for testing a SOAP service. I also get dropped connections all over the place, so maybe this is to be expected with such a large number of concurrent threads.