title: How to resolve java net ConnectException Connection refused connect even server is up
body: <p>I am using Httpurlconnection to send request from my jboss server to my device. The Device has been build up by cgi. </p>
  
  <p>When server sends request from multiple thread at a time to device, some thread got an exception as  java.net.ConnectException: Connection refused. but the device is sending response to server in some delay. I have set httpurlconnection timeout as 30 seconds(3000 milliseconds). </p>
  
  <p>But the error has come only when multiple thread sending it at same time.</p>
  
  <p>Does any one know please guide me to resolve the problem.</p>
  
  <pre><code>java.net.ConnectException: Connection refused: 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:519)
      at java.net.Socket.connect(Socket.java:469)
      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.http.HttpClient.&lt;init&gt;(HttpClient.java:233)
      at sun.net.www.http.HttpClient.New(HttpClient.java:306)
      at sun.net.www.http.HttpClient.New(HttpClient.java:323)
      at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:852)
      at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:793)
      at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:718)
      at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1041)
  </code></pre>