title: Java HttpsURLConnection outbound limit?
body: <p>I am creating a test app to load test a comet servlet by creating a bunch of outbound https connections (each looping in its own thread).</p>
  
  <p>Is there a limit on the number of concurrent outbound http requests? If so, is it an OS level issue (xp 32bit) or Java?  I get the following exception when running around 100 connections. The error does not occur instantly but after anywhere between 50-150 loops (sometimes more), leading me to suspect that it actually might be me not releasing resources correctly:</p>
  
  <pre><code>java.net.BindException: Address already in use: connect
      at java.net.PlainSocketImpl.socketConnect(Native Method)
      at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
      at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
      at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
      at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
      at java.net.Socket.connect(Socket.java:529)
      at com.sun.net.ssl.internal.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:559)
      at         com.sun.net.ssl.internal.ssl.BaseSSLSocketImpl.connect(BaseSSLSocketImpl.java:141)
   at sun.net.NetworkClient.doConnect(NetworkClient.java:163)
   at sun.net.www.http.HttpClient.openServer(HttpClient.java:394)
   at sun.net.www.http.HttpClient.openServer(HttpClient.java:529)
   at sun.net.www.protocol.https.HttpsClient.&lt;init&gt;(HttpsClient.java:272)
   at sun.net.www.protocol.https.HttpsClient.New(HttpsClient.java:329)
   at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(AbstractDelegateHttpsURLConnection.java:172)
   at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:916)
   at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:158)
   at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1177)
   at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:234)
   at fqexconnectiontesting.FQEXHttpClient.run(FQEXHttpClient.java:158)
   at java.lang.Thread.run(Thread.java:662)
  </code></pre>
  
  <p>My code:</p>
  
  <pre><code>while(true){
  try{                    
  connection =(HttpsURLConnection) url.openConnection();                    
  connection.setDoOutput(true);
  connection.setRequestProperty("keep-alive", "true");
  connection.setRequestMethod("GET");
  input = new DataInputStream( connection.getInputStream() ); 
  b = new byte[4096];                    
  totalBytes += input.read(b);                    
  input.close();
  b = null;         
  connection.disconnect();                                        
  connection = null;
  Thread.sleep(100);
  }
  </code></pre>
  
  <p>Any ideas appreciated.</p>
  
  <p>Thanks,
  Dazz</p>