2

I am using Httpurlconnection to send request from my jboss server to my device. The Device has been build up by cgi.

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).

But the error has come only when multiple thread sending it at same time.

Does any one know please guide me to resolve the problem.

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.<init>(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)
3
  • Can you explain the phrase 'the error has come only when multiple thread invoking or sending it'? Commented Nov 27, 2013 at 12:46
  • Hi keerthi. It's occurred only when multiple thread sending request at same time.i will edit that line Commented Nov 27, 2013 at 12:54
  • The server has connection limit per IP and is refusing. Commented Nov 27, 2013 at 13:00

1 Answer 1

2

If a single thread connects fine, every time, but some threads running concurrently get this exception, then this is most likely due to a limited number of connections available. Can you change how many concurrent connections are available on the device? If not, then you can try limiting the number of threads that attempt to make the connection.

EDIT: If you can't modify the "device" application or configure it for debugging, then try to see the exact behavior of the threads that are attempting to connect to it. Use a debugger on the client (which is your jboss server in this case) or log debug info from the threads showing connect and release times to see if the exception always occurs when multiple threads are attempting to connect simultaneously (as opposed to threads finishing the connection before other threads connect or timeout).

If it turns out that it really is a connection limit causing the issue, you could try creating a singleton connection object that is shared among threads. This will seriously bottle neck the jboss application when multiple threads attempt to connect. If that isn't acceptable, you'll have to come up with a new solution (e.g. multiple devices, write your own app, etc).

Sign up to request clarification or add additional context in comments.

3 Comments

@Murali I would debug this issue so that I'm sure that's the problem before I implement a fix. Can you alter the application on the device or configure it to output debug information?
i am not able to alter the application on device. we have to modify in server side application only. thats the problem
@Murali See the edit of my answer. I'm going to add more, too.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.