I assume that since it's possible to lookup web addresses in Java, the JVM is somehow finding a DNS server to use. Am I correct in that assumption, and if so can I retrieve the name of that DNS server somehow? David Weitzman
The "java.naming.provider.url" property is used by the JNDI/DNS service provider to configure how to communicate with DNS server(s). If this property has not been set or if its value specifies neither a hostname nor port, then on releases earlier than the Java 2 SDK, v 1.4.1, the hostname and port default to "localhost" and 53, respectively. Under the same circumstances on the Java 2 SDK, v 1.4.1, the DNS provider will attempt to determine and use the server(s) configured for the underlying platform (on Solaris or Linux, for example, the provider will read the /etc/resolv.conf file). If DNS has not been configured on the underlying platform, the hostname and port default to "localhost" and 53. This change affects applications that are deployed in an environment in which DNS has been configured in the underlying platform to use servers other than "localhost" and port 53, and at the same time expect "localhost" and port 53 to be used without specifying them explicitly. The affected applications will use a different DNS server than expected when migrating from Java 2 SDK v 1.4 to Java 2 SDK v 1.4.1. The workaround is for the application to explicitly specify "localhost" in the URL.
The JNDI DNS stuff is actually what I'm trying to use. Does that mean that on 1.4.1 it would 'just work'? I was hoping I wouldn't be able to think of a good reason to justify switching to 1.4.1...
The JVM by default will use your machine's underlying TCP stack to lookup IP addresses. I know of no way to get the name of the DNS server your machine is using, except for parsing OS configuration files which is platform dependent. The JNDI DNS stuff probably isn't what your looking for. That release note is refering to the JNDI DNS service provider Sun implemented with release 1.4.0. If you use it, you usually manually specify the DNS servers for Java to use. Here's a link to a page on my site that may help; http://www.buzzsurf.com/java/dns
Actually I've already taken care of this. I was correct that in 1.4.1 it will 'just work', but I decided to included an alternate dnsjava based implementation in my program. I'll have to look at your dnsjavans stuff though -- sounds interesting. I had never considered that one implementation might be slower than another. Do you happen to know offhand whether either the JNDI or dnsjava implementations cache MX records? I'll probably want to cache them myself anyway, but I'm not sure how long I ought to hold cached data. [ November 01, 2002: Message edited by: David Weitzman ]
I don't know offhand, but I'll bet dnsjava caches MX records. FYI, standard TCP stack resultions are cached in memory also, so depending on what the application is, you have to be very carefull about setting appropriate parameters. My company does website monitoring, so it's critical that we cache no resolutions to verify someone's website is down, and not just cached locally. Plus we're doing around 20k DSN resolutions a minute. If your application is a web spider or similar, you'll want to use as large a DNS cache as possible. We find that DNS resolutions are responsible for a large part of the time is takes to create a socket connection. If you just writing some kind of a server application, you probably don't need to wory about any of this; standard DNS setting will usually work.
I'm implementing a mail server. Eventually I'd like it to be able to handle large volumes of mail. Since I'm just a normal guy trying to write an open source mail server, I don't actually know how many MX records a run-of-the-mill enterprise server looks up in a minute. It's probably best to plan for the worst, although a huge cache begins to eat away at memory. I'll have to work out a reasonable size when I'm further along. Thanks for the info. Oh, by the way: Welcome to JavaRanch!
All that thinking. Doesn't it hurt? What do you think about this tiny ad?