mibutec
mibutec

Reputation: 2997

Measure DNS-Lookup time with java

I need to measure DNS Lookup time out of a java application. My idea is to measure the execution-time of InetAddress.getByName("myName"). What I'm not sure about is if this call is cached by operating-system. Can anybody tell me if so?

Is there maybe a better way to do that?

Upvotes: 1

Views: 1512

Answers (2)

Santosh
Santosh

Reputation: 17923

I am not sure about the Operating System but Java has its own DNS cache which are configurable via system properties. Please checkout this link for more details.

EDIT:

Your use case warrants disable DNS caching.

Upvotes: 3

ewan.chalmers
ewan.chalmers

Reputation: 16255

Regarding caching, the javadoc of InetAddress says that:

The InetAddress class has a cache to store successful as well as unsuccessful host name resolutions. 

So whatever about the OS, Java caches the results.

Read on, and you can see JVM args you can specify to modify the default caching behaviour.

Upvotes: 3

Related Questions