Sometimes we face issues like the thread , which trying to connect the url ,hangs for infinite time. The connection may be over http,ftp or scp protocol.But really it is painful to debug the issue.But there are some system level configuration provided by java, so that we can we can solve this problem.
So lets start with some simple definitions.
The timeout (in milliseconds) to establish the connection to the host.For example for http connections it is the timeout when establishing the connection to the http server. For ftp connection it is the timeout when establishing the connection to ftp servers.For scp connection it is the time out for establishing the scp connection.
The property provided by sun for connectionTimeOut is
sun.net.client.defaultConnectTimeout (default: -1)
Note that here -1 means infinite timeout.
The timeout (in milliseconds) when reading from input stream when a connection is established to a resource.It is the timeout between two consecutive packets from the socket.
The property provided by sun for readTimeOut is
sun.net.client.defaultReadTimeout (default: -1)
It determines if an unsuccessful HTTP POST request will be automatically resent to the server. Unsuccessful post means in this case the server did not send a valid HTTP response or an IOException occurred.And it defaults to true in system level.
The property provided by sun for retry post fails is
We can set the property like
-Dsun.net.client.defaultReadTimeout =timeinmiliseconds
-Dsun.net.client.defaultReadTimeout =timeinmiliseconds
-Dsun.net.http.retryPost =false
For more details please follow the oracle doc.
So lets start with some simple definitions.
ConnectionTimeOut:
The timeout (in milliseconds) to establish the connection to the host.For example for http connections it is the timeout when establishing the connection to the http server. For ftp connection it is the timeout when establishing the connection to ftp servers.For scp connection it is the time out for establishing the scp connection.
The property provided by sun for connectionTimeOut is
sun.net.client.defaultConnectTimeout (default: -1)
Note that here -1 means infinite timeout.
ReadTimeOut:
The timeout (in milliseconds) when reading from input stream when a connection is established to a resource.It is the timeout between two consecutive packets from the socket.
The property provided by sun for readTimeOut is
sun.net.client.defaultReadTimeout (default: -1)
Retry If Post Fails:
It determines if an unsuccessful HTTP POST request will be automatically resent to the server. Unsuccessful post means in this case the server did not send a valid HTTP response or an IOException occurred.And it defaults to true in system level.
The property provided by sun for retry post fails is
- sun.net.http.retryPost (default: true)
We can set the property like
-Dsun.net.client.defaultReadTimeout =timeinmiliseconds
-Dsun.net.client.defaultReadTimeout =timeinmiliseconds
-Dsun.net.http.retryPost =false
For more details please follow the oracle doc.
No comments:
Post a Comment