Where check/set timeout when java.net.UnknownHostException is thrown?
Occasionally my code tries to connect to a non-existing location and throws java.net.UnknownHostException what is acceptable case in my app.
The problem I have is that it takes roughly about 20sec before the exception is thrown and it slows down the whole application.
The webserver version is Tomcat 7.0.37. I have tried change timeout settings (to 2sec) in the server.xml for following connectors:
Connector port="8009" protocol="AJP/1.3" redirectPort="8443" connectionTimeout="2000"
Connector port="8080" protocol="HTTP/1.1" connectionTimeout="2000" redirectPort="8443"
As I use HttpURLConnection I would expect the connection timeout setting for port 8080 to take effect, but it does not seem to be true.
I also tried to set the timeout within the code:
HttpURLConnection connection = (HttpURLConnection)url.openConnection();
connection.setConnectTimeout(1000);
Reader reader= new InputStreamReader((InputStream) connection.getContent());
But this did not work neither, any ideas? Am I missing something?
ta