7

I'm building a fast web crawler and I need to have multithreaded DNS resolution, so I picked up a multithreaded DNS service provider called dnsjava. Unfortunately, I can't figure out how to replace the default DNS Service Provider.

I went over the README file for dnsjava, but the instructions are not very through.

Replacing the standard Java DNS functionality:

Beginning with Java 1.4, service providers can be loaded at runtime. To load the dnsjava service provider, build it as explained above and set the system property:

sun.net.spi.nameservice.provider.1=dns,dnsjava

This instructs the JVM to use the dnsjava service provide for DNS at the highest priority.

There are a couple of things that I'm unclear on:

  1. Where do I place the dnsjava.jar?
  2. Where is the system property supposed to be set (is it programmatic or some type of file change)?

I'm running on a Windows 7 machine and I'm not sure what I need to do to find/modify the system properties... help!?

Update:
Got it: System.setProperty("sun.net.spi.nameservice.provider.1","dns,dnsjava");

Kiril
  • 39,672
  • 31
  • 167
  • 226
  • Are you sure `System.setProperty("sun.net.spi.nameservice.provider.1","dns,dnsjava");` works to be using DNSJava first, and only then falling back to the system DNS? – Robert Fischer Jan 09 '14 at 13:59

1 Answers1

4

A wild guess.

  1. Put the dnsjava.jar file in the classpath of your application.
  2. Have the system property set before launching the main method in your application.
Thorbjørn Ravn Andersen
  • 73,784
  • 33
  • 194
  • 347
  • do I set the system property programatically? I created a Properties instance and I tried to find if it contains the key "sun.net.spi.nameservice.provider", but it didn't have it... am I on the right track? – Kiril Apr 14 '11 at 19:03
  • It is most likely not defined yet, so it falls back to the default values. I would suggest you ask Google about "sun.net.spi.nameservice.provider.1" and see what the results say. – Thorbjørn Ravn Andersen Apr 14 '11 at 19:09
  • 2
    Found it... `System.setProperty("sun.net.spi.nameservice.provider.1")`, THANKS! – Kiril Apr 14 '11 at 19:14
  • would you happen to know if there is a way to verify if the dnsjava Service Provider is actually being used? – Kiril Apr 14 '11 at 19:27
  • Sorry no. I would suggest having a closer look at the documentation to see what they recommend you use for debugging. – Thorbjørn Ravn Andersen Apr 14 '11 at 20:03
  • You can start the application in debug mode and connect to it with your IDE of choice. Set the breakpoint on `DNSJavaNameService.lookupAllHostAddr(String host)` When you perform your lookup, you should be able to see it enter this method. – John Yeary Oct 17 '17 at 15:42