使用以下代码:
try {
System.out.println(new Date());
InetAddress hostName = InetAddress.getLocalHost();
System.out.println(new Date());
} catch (UnknownHostException e) {
e.printStackTrace();
}
我得到以下输出:
Thu Oct 22 20:58:22 BST 2015
Thu Oct 22 20:58:52 BST 2015
换句话说,需要30秒才能执行。机器是具有Java 1.8.0_60的2015 Macbook Pro。
为什么要花这么长时间?
InetAddress.getLocalHost(),看看它在哪里花费时间