aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/util/NetUtil.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/util/NetUtil.java')
-rw-r--r--src/main/java/com/google/devtools/build/lib/util/NetUtil.java21
1 files changed, 19 insertions, 2 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/util/NetUtil.java b/src/main/java/com/google/devtools/build/lib/util/NetUtil.java
index f22146a71d..dc2ce8867e 100644
--- a/src/main/java/com/google/devtools/build/lib/util/NetUtil.java
+++ b/src/main/java/com/google/devtools/build/lib/util/NetUtil.java
@@ -21,14 +21,31 @@ import java.net.UnknownHostException;
*/
public final class NetUtil {
+ private static String hostname;
+
private NetUtil() {
}
/**
+ * Returns the *cached* short hostname (computed at most once per the lifetime of a server). Can
+ * take seconds to complete when the cache is cold.
+ */
+ public static String getCachedShortHostName() {
+ if (hostname == null) {
+ synchronized (NetUtil.class) {
+ if (hostname == null) {
+ hostname = computeShortHostName();
+ }
+ }
+ }
+ return computeShortHostName();
+ }
+
+ /**
* Returns the short hostname or <code>unknown</code> if the host name could not be determined.
- * Performs reverse DNS lookup and can take seconds to complete!
+ * Performs reverse DNS lookup and can take seconds to complete.
*/
- public static String findShortHostName() {
+ private static String computeShortHostName() {
try {
return InetAddress.getLocalHost().getHostName();
} catch (UnknownHostException e) {