Hi I am working on Java application and deployed on Jboss
,windows 8 server. In my server code i use HttpUrlconnection
for communicating with my products.
I would like to set a time limit for evey connection to connect with my product. So that i use HttpUrlconnection.setconnectionTimeout(30000)
for 30 seconds time limit. But the connection has been refused at 9 minutes. HttpUrlconnection.setconnectionTimeout()
is not working at this time.
I have found the problem that has been happened by TCP Timeout and retransmission limit has been set in windows 8 server. By default TCP retransmission limit is 2. after 2 tries, the connection will be abandoned or refused.
My question is that How to avoid this problem from java side without changing Windows registry files? It means that have any possiblities to settimeout or retry TCP SYN/RST/ACK mechanism to avoid connection refused problem.
Does any one know, please help me to solve this issue
url = new URL(requestURL);
HttpURLConnection connection = (HttpURLConnection)
url.openConnection();
connection.setRequestMethod("GET");
connection.setUseCaches(false);
connection.setDoInput(true);
connection.setDoOutput(true);
connection.setConnectTimeout(30000
connection.setReadTimeout(30000;
try {
// Get Response
inputStream = connection.getInputStream();
} catch (IOException e) {
//
}
The Exception is below
java.net.ConnectException: Connection refused: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(Unknown Source)
at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at sun.net.NetworkClient.doConnect(Unknown Source)
at sun.net.www.http.HttpClient.openServer(Unknown Source)
at sun.net.www.http.HttpClient.openServer(Unknown Source)
at sun.net.www.http.HttpClient.<init>(Unknown Source)
at sun.net.www.http.HttpClient.New(Unknown Source)
at sun.net.www.http.HttpClient.New(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.connect(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)