Reputation: 198318
Related to this question: How to set the timeout for socket when looking for host?, I found it important to know the default timeout for a host lookup
If the timeout is short, e.g. several minutes, I think it's safe to do nothing with it. If it's long, e.g several hours, I have to set timeout for it.
What's the default timeout for socket when looking up host?
Upvotes: 2
Views: 5081
Reputation: 76908
The JNDI Docs provide this information:
The DNS provider submits UDP queries using the following exponential backoff algorithm. The provider submits a query to a DNS server and waits for a response to arrive within a timeout period (1 second by default). If it receives no response within the timeout period, it queries the next server, and so on. If the provider receives no response from any server, it doubles the timeout period and repeats the process of submitting the query to each server, up to a maximum number of retries (4 by default).
So it depends on the number of DNS servers your configuration includes, but with the default initial value of one second it's 31 seconds per server if all are failing; 1 + 2 + 4 + 8 + 16 = 31. (initial try + 4 retries)
Upvotes: 3
Reputation: 1777
What about this ?
import java.io.IOException;
import java.net.Socket;
import java.net.UnknownHostException;
/**
*
*/
public class SocketTimeoutTest {
public static void main(String[] args) {
long startMillis = System.currentTimeMillis();
try {
Socket socket = new Socket("www.test123.com", 80);
} catch (UnknownHostException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
long endMillis = System.currentTimeMillis();
System.out.println("Timout: " + (endMillis - startMillis));
}
}
Upvotes: -3