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

后端 未结 2 1492
渐次进展
渐次进展 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:12

    Some non-standard implmentation of this method may ignore the specified timeout. See this setConnectTimeout

    0 讨论(0)
  • 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

    0 讨论(0)
提交回复
热议问题