ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From maart...@apache.org
Subject svn commit: r657200 - /ant/ivy/core/trunk/src/java/org/apache/ivy/util/HostUtil.java
Date Fri, 16 May 2008 20:42:21 GMT
Author: maartenc
Date: Fri May 16 13:42:21 2008
New Revision: 657200

URL: http://svn.apache.org/viewvc?rev=657200&view=rev
Log:
Cache the localhost name as suggested in IVY-817

Modified:
    ant/ivy/core/trunk/src/java/org/apache/ivy/util/HostUtil.java

Modified: ant/ivy/core/trunk/src/java/org/apache/ivy/util/HostUtil.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/util/HostUtil.java?rev=657200&r1=657199&r2=657200&view=diff
==============================================================================
--- ant/ivy/core/trunk/src/java/org/apache/ivy/util/HostUtil.java (original)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/util/HostUtil.java Fri May 16 13:42:21 2008
@@ -25,6 +25,9 @@
  * 
  */
 public final class HostUtil {
+    
+    private static String localHostName = null;
+    
     /**
      * This default constructor is to hide this class from initialization through other classes.
      */
@@ -38,10 +41,13 @@
      * @return The name of the current "local" Host.
      */
     public static String getLocalHostName() {
-        try {
-            return InetAddress.getLocalHost().getHostName();
-        } catch (UnknownHostException e) {
-            return "localhost";
+        if (localHostName == null) {
+            try {
+                localHostName = InetAddress.getLocalHost().getHostName();
+            } catch (UnknownHostException e) {
+                localHostName = "localhost";
+            }
         }
+        return localHostName;
     }
 }



Mime
View raw message