|
DNS Resolution in Java 1.4 pwc21@yahoo.com Java's networking abilities have been improved quite a bit in version 1.4. Refer to the following URL for some important properties you can set; http://java.sun.com/j2se/1.4/docs/guide/net/properties.html Most notably; networkaddress.cache.ttl networkaddress.cache.negative.ttl These can affect how your DNS resolutions are cached in Java. It's also interesting to note that in Java 1.4 they finally added support for a socket timeout in the URLConnection class by setting the sun.net.client.defaultConnectTimeout and sun.net.client.defaultReadTimeout parameters. In addition, you can now choose to circumvent the standard Java name resolution system and use their "pluggable" archecture. They call it a DNS Service Provider. Basically, a DNS Service Provider is a set of java classes (written by you or Sun or someone else) that will perform your DNS resolutions, instead of using the standard method which uses the machine's TCP stack. You set some parameters, and it will use the jar you tell it to for lookups. (Your classes have to implement some specific interfaces for this to work.) In this way, you can get total control over how DNS resolutions are performed, without altering any Java code to perform lookups manually. Sun has provided a JNDI based DNS Service Provider jar with Java 1.4, it's in jre/lib/ext/dnsns.jar. Details on it can be found here; http://java.sun.com/j2se/1.4/docs/guide/jndi/jndi-dns.html I've tried their Service Provider and I'm sorry to say it's pathetic, at least for high performance requirements. There is another DNS resolver called dnsjava that provides much better performance; http://www.xbill.org/dnsjava/ dnsjava can do lots of cool things if you set the right parameters. dnsjava isn't a DNS Service Provider although, so up until Java 1.4 to use it you had to do the lookups manually in your Java code. If you were using the URLConnection class, this is impossible. I spent some time and wrote a connector I call dnsjavans, which lets you use dnsjava as a Java 1.4 DNS Service Provider. With it, you can reap all the benefits of the dnsjava package without having to alter any code to force manual resolutions. You can download my dnsjavans.jar here. dnsjavans is not part of the dnsjava package, which is written and maintained by Brian Welling. It's a separate jar that allows you to use dnsjava as a Java 1.4 DNS Service Provider. It requires you also have the dnsjava jar in your classpath. Getting Java to use a DNS Service Provider can be very confusing. You have to set at least one system parameter; sun.net.spi.nameservice.provider.1=dns,dnsjava And you'll probably want to set; sun.net.spi.nameservice.nameservers=<comma delimited list of name
servers> |