开发者

java.net.UnknownHostException - intermittant issues

I have a Web Service written in Java using Java 1.6.0_17.

One of the services goes out and screen scraps another one of my servers using the following code:

HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
connection.connect();

InputStream stream = connection.getInputStream();

return convertStreamToString(stream);

For the most part, about 80% of the time (very rough guess) this seems to work fine however the rest of the time I am getting the following exception when I get to the connection.connect() part o开发者_JAVA百科f the code:

java.net.UnknownHostException: {my server name was here}
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:177)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
at java.net.Socket.connect(Socket.java:525)
at java.net.Socket.connect(Socket.java:475)

I replaced the URL of our server with {my server name was here} in the logs above. I am able to run nslookup and the server resolves fine.

The Web Service runs on a JBoss 4.2.3 server on a Windows 2003 Standard x64 Edition Service Pack 2 server.

I do know that the Unknownhost exception means the server name could not be resolved, however I am struggling with why this is happening intermittently. I would prefer to not resolve the host name via the host file because in the future, when we change hosts, I would like to be able to change the DNS and not worry about the host files.

Does anyone have any suggestions on how to resolve this issue? Thank you in advance for any help you can provide.


You have a flaky DNS server configuration. Setup some monitoring to prove it to the system administrators. This can be as simple as a cron job with a shell script or as complicated as a Nogios monitoring system.

We had similar issues when we migrated from Java5 to Java6 since before Java6 the DNS resolved address was cached for ever (or till the JVM was stopped, whichever came first). So on some flaky servers we had suddenly issues when the Java6 expired DNS entries.

We were aware of the problem though because of the inverse issue : we had redundant LDAP servers in DNS round robin, which of course does not work when the address is cached forever.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜