Reputation: 1911
My goal is to check a big list of domains as fast as possible. The method InetAddress.getByName()
seems to be a little bit slow for me. In PHP there's gethostbyname('www.example.com')
which seems to work faster. Is there an equivalent in Java which is faster? or is there a way to speed it up?
Upvotes: 1
Views: 561
Reputation: 1083
NSLookups take time because of the network infrastructure, but you can make the check in paralell. Write a thread that make the lookup and run multiple instances of it in paralell.
class LookUpThread implements Runnable {
String name;
public LookUpThread() {
}
public LookUpThread(String Name) {
this.name = Name;
}
public void run()
{
try
{
InetAddress address = InetAddress.getByName(this.name);
System.out.println(address.getHostAddress());
}
catch (Exception E) {
System.out.println("Exception " + E.getMessage());
}
}
}
And in you main:
String[] adds = new String[]{"example.com", "example.com"};
for(int i = 0; i < adds.length; i++)
new LookUpThread(adds[i]).run();
Upvotes: 1