简体   繁体   中英

Why does getLocalhost() freeze sometimes?

With JRE6 (SUN VM on Windows XP), getLocalhost() freezes sometimes.

Interestingly, if in the debugger in Eclipse, it does not freeze. I narrowed it down to a single getLocalhost() call using old school println. There is nothing particularly special about the code, that I can see.

Has anyone else seen this problem?

You did not specify how long it freezes for... or did you mean completely frozen, never returning.

If the local host name (returned from a JNI call) is not "localhost", the IP address for the local name is resolved using InetAddress.getAddressFromNameService(). This is a DNS call that could conceivably block for an unspecified amount of time finding and accessing the name server.

使用wireshark来查看您的DNS是否花费很长时间来响应。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM