Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance
Java decentralizedintranet-searchintranet-search-enginep2pp2p-networkprivacyprivacy-protectionsearch-enginesearchenginewebweb-search-enginewebsearchwebseearch-engine
added load and deadlock detector in Memory util
orbiterb71d13a014a7
diff --git a/source/net/yacy/cora/util/Memory.java b/source/net/yacy/cora/util/Memory.javaindex 2e0ab19e7..33b483206 100644--- a/source/net/yacy/cora/util/Memory.java+++ b/source/net/yacy/cora/util/Memory.java@@ -20,6 +20,9 @@package net.yacy.cora.util;+import java.lang.management.ManagementFactory;+import java.lang.management.ThreadInfo;+public class Memory {private static final Runtime runtime = Runtime.getRuntime();@@ -45,7 +48,7 @@ public class Memory {* @return bytes*/public static final long maxMemory() {- return runtime.maxMemory();+ return runtime.maxMemory(); // can be Long.MAX_VALUE if unlimited}/**@@ -63,5 +66,34 @@ public class Memory {public static final long used() {return total() - free();}-++ /**+ * get the system load within the last minute+ * @return the system load or a negative number if the load is not available+ */+ public static double load() {+ return ManagementFactory.getOperatingSystemMXBean().getSystemLoadAverage();+ }++ /**+ * find out the number of thread deadlocks. WARNING: this is a time-consuming task+ * @return the number of deadlocked threads+ */+ public static long deadlocks() {+ long[] deadlockIDs = ManagementFactory.getThreadMXBean().findDeadlockedThreads();+ if (deadlockIDs == null) return 0;+ return deadlockIDs.length;+ }++ /**+ * write deadlocked threads as to the log as warning+ */+ public static void logDeadlocks() {+ long[] deadlockIDs = ManagementFactory.getThreadMXBean().findDeadlockedThreads();+ if (deadlockIDs == null) return;+ ThreadInfo[] infos = ManagementFactory.getThreadMXBean().getThreadInfo(deadlockIDs, true, true);+ for (ThreadInfo ti : infos) {+ ConcurrentLog.warn("DEADLOCKREPORT", ti.toString());+ }+ }}