Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoreyuen2011-09-09 18:37:30 +0000
committereyuen2011-09-09 18:37:30 +0000
commit19952a8e3b4eb16f046cd40e1b5a824c57b2b1c4 (patch)
tree11c0c5d4ce40e5c45f6385a10741d82548a95e66 /plugins/org.eclipse.wst.server.core/servercore/org/eclipse
parent005c8b598a8e79440be66b1911840b3fcd9ddf5c (diff)
downloadwebtools.servertools-19952a8e3b4eb16f046cd40e1b5a824c57b2b1c4.tar.gz
webtools.servertools-19952a8e3b4eb16f046cd40e1b5a824c57b2b1c4.tar.xz
webtools.servertools-19952a8e3b4eb16f046cd40e1b5a824c57b2b1c4.zip
[337763] SocketUtil.isLocalHost still freezing, affecting Server Editor load time
Diffstat (limited to 'plugins/org.eclipse.wst.server.core/servercore/org/eclipse')
-rw-r--r--plugins/org.eclipse.wst.server.core/servercore/org/eclipse/wst/server/core/util/SocketUtil.java38
1 files changed, 35 insertions, 3 deletions
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<String> localHostCache = new HashSet<String>();
+ protected static Set<String> localHostCache = new HashSet<String>();
private static Set<String> notLocalHostCache = new HashSet<String>();
private static Map<String, CacheThread> threadMap = new HashMap<String, CacheThread>();
@@ -258,7 +258,7 @@ public class SocketUtil {
* </p><p>
* 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 <code>false</code>
* even though it may later determine that the host address is a local host)
* </p><p>
@@ -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 {

Back to the top