From 19952a8e3b4eb16f046cd40e1b5a824c57b2b1c4 Mon Sep 17 00:00:00 2001 From: eyuen Date: Fri, 9 Sep 2011 18:37:30 +0000 Subject: [337763] SocketUtil.isLocalHost still freezing, affecting Server Editor load time --- .../eclipse/wst/server/core/util/SocketUtil.java | 38 ++++++++++++++++++++-- 1 file changed, 35 insertions(+), 3 deletions(-) (limited to 'plugins/org.eclipse.wst.server.core/servercore/org/eclipse') diff --git a/plugins/org.eclipse.wst.server.core/servercore/org/eclipse/wst/server/core/util/SocketUtil.java b/plugins/org.eclipse.wst.server.core/servercore/org/eclipse/wst/server/core/util/SocketUtil.java index e50f3b114..cb2ea4f35 100644 --- a/plugins/org.eclipse.wst.server.core/servercore/org/eclipse/wst/server/core/util/SocketUtil.java +++ b/plugins/org.eclipse.wst.server.core/servercore/org/eclipse/wst/server/core/util/SocketUtil.java @@ -37,7 +37,7 @@ public class SocketUtil { protected static final Object lock = new Object(); - private static Set localHostCache = new HashSet(); + protected static Set localHostCache = new HashSet(); private static Set notLocalHostCache = new HashSet(); private static Map threadMap = new HashMap(); @@ -258,7 +258,7 @@ public class SocketUtil { *

* On machines where the network configuration of the machine is bad or the * network has problems, the first call to this method will always return after - * 250ms, even if the caching is not complete. At that point it may return + * 350ms, even if the caching is not complete. At that point it may return * "false negative" results. (i.e. the method will return false * even though it may later determine that the host address is a local host) *

@@ -293,7 +293,6 @@ public class SocketUtil { try { localHostaddr = InetAddress.getLocalHost(); if (host.equals(localHostaddr.getHostName().toLowerCase()) - || host.equals(localHostaddr.getCanonicalHostName().toLowerCase()) || host.equals(localHostaddr.getHostAddress().toLowerCase())){ synchronized (lock) { localHostCache.add(host); @@ -306,6 +305,39 @@ public class SocketUtil { } } + // Bug 337763 - the InetAddress's getCanonicalHostName was removed from the simple case + // to be called in its own separate thread. This was due to the call being platform + // dependent and in some cases, taking up to 10 seconds to return. + // + // The cached thread may perform operations that are expensive. Therefore, to handle + // the case where the canonical host name returns quickly, a thread that terminates + // after 100ms is used. + try { + final String hostFinal = host; + final InetAddress localHostaddrFinal = localHostaddr; + Thread compareCanonicalHostNameThread = new Thread(){ + public void run(){ + boolean isLocal = + hostFinal.equals(localHostaddrFinal.getCanonicalHostName().toLowerCase()); + if (isLocal){ + synchronized (lock) { + localHostCache.add(hostFinal); + } + } + } + }; + compareCanonicalHostNameThread.start(); + compareCanonicalHostNameThread.join(100); + // Check cache again + if (localHostCache.contains(host)){ + return true; + } + } catch (Exception e){ + if (Trace.WARNING) { + Trace.trace(Trace.STRING_WARNING, "Comparing host with local host conical host name failed", e); + } + } + // check for current thread and wait if necessary boolean currentThread = false; try { -- cgit v1.2.3