URLConnection.setConnectTimeout() does not work when DNS is unreachable

后端 未结 2 1494
渐次进展
渐次进展 2021-01-28 07:17

Here is my code :

URL u = new URL(\"http://www.google.com\");
        URLConnection conn = u.openConnection();
        conn.setConnectTimeout(3000);
        conn         


        
2条回答
  •  深忆病人
    2021-01-28 08:15

    I found a post that can work around it. Use another thread to query DNS to simulate timeout: http://thushw.blogspot.sg/2009/11/resolving-domain-names-quickly-with.html

提交回复
热议问题