• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 222
  • Last Modified:

DNS oddity

Given the following code:

    InetSocketAddress isaCurrent = new InetSocketAddress("messenger.hotmail.com", 1863);
    sm_logger.info("Connecting to server '" + isaCurrent + "'.");

at the tail end of a process that had been running for upwards of a week this code resulted in the following log4j output:
    2006-06-21 23:34:50,797 INFO - Connecting to server 'messenger.hotmail.com/'.

30 seconds later after the process had been stopped and re-started the following lof4j ouput resulted:

    2006-06-21 23:35:28,250 INFO - Connecting to server 'messenger.hotmail.com/'.

The obvious difference between the two being that the address of 'messenger.hotmail.com' had changed to from  Assuming that the DNS entry had indeed been changed prior to the first log statement, I'm wondering why it took restarting the process for the address change to be recognized in my Java code?

Is it possible that the JVM caches DNS resolves and uses cached values for as long as the process runs going forward?
1 Solution
yes, you are right. By default, JVM caches successful name lookups forever. However, you can change this by setting the following system property:


The value -1 (by default) indicates that the lookup would be cached forerver. If this is set is 5, it would cache the successful lookup for 5 secs
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now