for (NameService nameService : nameServices) { try { /* * Do not put the call to lookup() inside the * constructor. if you do you will still be * allocating space when the lookup fails. */ addresses = nameService.lookupAllHostAddr(host); success = true; break; } catch (UnknownHostException uhe) { if (host.equalsIgnoreCase("localhost")) { InetAddress[] local = new InetAddress[] { impl.loopbackAddress() }; addresses = local; success = true; break; } else { addresses = unknown_array; success = false; ex = uhe; } } }
这是真正执行DNS查询的地方,而且可以看到是通过NameService链来依次解析的。其中nameServices是InetAddress的一个成员变量:
/* Used to store the name service provider */ private static List<NameService> nameServices = null;
通过static块进行初始化的: