Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance
Java decentralizedintranet-searchintranet-search-enginep2pp2p-networkprivacyprivacy-protectionsearch-enginesearchenginewebweb-search-enginewebsearchwebseearch-engine
fix for bug in formatting in ThreadDump and added hint for linux/Mac users that they may use the LOCKED feature using the start option -l
orbiterc2a968c23fc4
diff --git a/htroot/Threaddump_p.java b/htroot/Threaddump_p.javaindex ca9b36dc8..644713fd4 100644--- a/htroot/Threaddump_p.java+++ b/htroot/Threaddump_p.java@@ -34,6 +34,7 @@ import java.util.ArrayList;import net.yacy.cora.protocol.RequestHeader;import net.yacy.kelondro.logging.ThreadDump;+import net.yacy.kelondro.util.OS;import de.anomic.search.Switchboard;import de.anomic.server.serverObjects;@@ -82,16 +83,16 @@ public class Threaddump_p {ThreadDump.appendStackTraceStats(appPath, buffer, traces, plain, null);} else {// write a thread dump to standard error output- /*- if (OS.canExecUnix) {- int pid = OS.getPID();- if (pid >= 0) try {OS.execSynchronous("kill -3 " + pid);} catch (IOException e) {}- }- */- try {- new ThreadDump().appendBlockTraces(buffer, plain);- } catch (IOException e) {- e.printStackTrace();+ File logFile = new File("yacy.log");+ if (ThreadDump.canProduceLockedBy(logFile)) {+ try {+ new ThreadDump(logFile).appendBlockTraces(buffer, plain);+ } catch (IOException e) {+ e.printStackTrace();+ }+ } else if (OS.canExecUnix) {+ ThreadDump.bufferappend(buffer, plain, "this thread dump function can find threads that lock others, to enable this function start YaCy with 'startYACY.sh -l'");+ ThreadDump.bufferappend(buffer, plain, "");}// generate a single thread dumpdiff --git a/source/net/yacy/kelondro/logging/ThreadDump.java b/source/net/yacy/kelondro/logging/ThreadDump.javaindex 633b5e49e..3b7a3eaf9 100644--- a/source/net/yacy/kelondro/logging/ThreadDump.java+++ b/source/net/yacy/kelondro/logging/ThreadDump.java@@ -28,7 +28,6 @@ package net.yacy.kelondro.logging;import java.io.BufferedReader;import java.io.ByteArrayInputStream;import java.io.File;-import java.io.FileInputStream;import java.io.IOException;import java.io.InputStream;import java.io.InputStreamReader;@@ -95,15 +94,26 @@ public class ThreadDump extends HashMap<ThreadDump.Thread, List<String>> implemereturn java.lang.Thread.getAllStackTraces();}- public ThreadDump() throws IOException {+ public static boolean canProduceLockedBy(File logFile) {++ // check os version+ if (!OS.canExecUnix) return false;++ // check if log file exists+ if (!logFile.exists()) return false;++ // check last modification date of log file+ if (System.currentTimeMillis() - logFile.lastModified() > 60000) return false;++ return true;+ }++ public ThreadDump(File logFile) throws IOException {super();// try to get the thread dump from yacy.log which is available when YaCy is started with// startYACY.sh -l- if (!OS.canExecUnix) return;-- File logFile = new File("yacy.log");- if (!logFile.exists()) return;+ if (!canProduceLockedBy(logFile)) return;long sizeBefore = logFile.length();// get the current process PID@@ -126,10 +136,6 @@ public class ThreadDump extends HashMap<ThreadDump.Thread, List<String>> implemeimportText(new ByteArrayInputStream(b));}- public ThreadDump(final File f) throws IOException {- this(new FileInputStream(f));- }-public ThreadDump(final InputStream is) throws IOException {super();importText(is);@@ -248,14 +254,14 @@ public class ThreadDump extends HashMap<ThreadDump.Thread, List<String>> implemebufferappend(buffer, plain, "");Map<Thread, Integer> locks = this.countLocks();- for (int i = 0; i < this.size() + 10; i++) {+ for (int i = this.size() + 10; i > 0; i--) {for (Map.Entry<Thread, Integer> entry: locks.entrySet()) {if (entry.getValue().intValue() == i) {bufferappend(buffer, plain, "holds lock for " + i + " threads:");final List<String> list = this.get(entry.getKey());if (list == null) continue;- bufferappend(buffer, plain, "Thread: " + entry.getKey());- for (String s: list) bufferappend(buffer, plain, " " + s);+ bufferappend(buffer, plain, "Thread= " + entry.getKey());+ for (String s: list) bufferappend(buffer, plain, " " + (plain ? s : s.replaceAll("<", "<").replaceAll(">", ">")));bufferappend(buffer, plain, "");}}