So you are going to try to get around network congestion by. . . creating more congestion?
Anyway, to specify a timeout, you could use the system network properties:
sun.net.client.defaultConnectTimeout (default: -1)
sun.net.client.defaultReadTimeout (default: -1)
These properties specify the default connect and read timeout (resp.) for the protocol handler used by java.net.URLConnection.
sun.net.client.defaultConnectTimeout specifies 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.
sun.net.client.defaultReadTimeout specifies the timeout (in milliseconds) when reading from input stream when a connection is established to a resource.
Java 1.4.2 SDK - Networking Properties
Or use the
Jakarta Commons HttpClient class, which specifies a timeout method.
You will have to write the logic to perform retries.