Java InetAddress.getHostName() taking a very long time to execute

后端 未结 3 556
暗喜
暗喜 2021-01-13 01:28

I have the following little code snippet:

        InetAddress address = InetAddress.getByName(host);
        if(address.isReachable(TIMEOUT_IN_MILLISECONDS))         


        
3条回答
  •  囚心锁ツ
    2021-01-13 01:43

    Some of the addresses need longer time to be resolved. InetAddress has a cache to store successful and unsuccessful resolutions. Also, make a threadpool. You can improve the performance

提交回复
热议问题