原因
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