Skip to content

Commit

Permalink
avoid forced execution of InetAddress.getLocalHost() at startup, beca…
Browse files Browse the repository at this point in the history
…use that hangs at some strangely declared linux configurations. The Domains.localHostAddresses object is first instantiated with a more simple logic and enriched with more host addresses using a concurrent thread that will not block a startup process.

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@6482 6c8d7289-2bf4-0310-a012-ef5d649a1542
  • Loading branch information
orbiter committed Nov 16, 2009
1 parent 013f337 commit fd0658c
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions source/net/yacy/kelondro/util/Domains.java
Expand Up @@ -522,20 +522,32 @@ public static void flushMissNameCache() {
public static String localHostName;
public static InetAddress[] localHostAddresses;
static {
localHostName = "127.0.0.1";
try {
localHostAddress = InetAddress.getByName("127.0.0.1");
localHostAddress = InetAddress.getByName(localHostName);
} catch (UnknownHostException e1) {}
try {
localHostAddress = InetAddress.getLocalHost();
localHostName = localHostAddress.getHostName();
} catch (UnknownHostException e) {
localHostName = "localhost";
}
try {
localHostAddresses = InetAddress.getAllByName(localHostName);
} catch (UnknownHostException e) {
localHostAddresses = new InetAddress[0];
}
new localHostAddressLookup().start();
}

public static class localHostAddressLookup extends Thread {
public void run() {
try {
localHostAddress = InetAddress.getLocalHost();
localHostName = localHostAddress.getHostName();
} catch (UnknownHostException e) {
localHostName = "127.0.0.1";
}
try {
localHostAddresses = InetAddress.getAllByName(localHostName);
} catch (UnknownHostException e) {
localHostAddresses = new InetAddress[0];
}
}
}

public static InetAddress myPublicLocalIP() {
Expand Down

0 comments on commit fd0658c

Please sign in to comment.