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?
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.
Your use case warrants disable DNS caching.
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.