原因
dubbo源碼中使用InetAddress.getLocalHost().getHostAddress()
方法獲取host,但是這個方法在部分環境中運行緩慢,卡5秒左右
測試代碼
public static void main(String[] args) throws Exception {
System.out.println("開始執行");
long start = System.currentTimeMillis();
System.out.println(InetAddress.getLocalHost().getHostAddress());
long end = System.currentTimeMillis();
System.out.println("執行完畢,用時" + (end - start) + "ms");
}
測試結果
解決辦法
在hosts文件中添加映射,將Dirk-Mac.local
換成你環境中執行System.out.println(InetAddress.getLocalHost());
所得到的結果中/
前的內容
127.0.0.1 Dirk-Mac.local
::1 Dirk-Mac.local