diff --git a/htroot/Threaddump_p.java b/htroot/Threaddump_p.java index 14ee3c8f7..a3e54b3b9 100644 --- a/htroot/Threaddump_p.java +++ b/htroot/Threaddump_p.java @@ -51,13 +51,17 @@ import de.anomic.data.htmlTools; import de.anomic.http.httpHeader; import de.anomic.plasma.plasmaSwitchboard; +import de.anomic.server.serverFileUtils; import de.anomic.server.serverObjects; import de.anomic.server.serverSwitch; +import de.anomic.tools.nxTools; import de.anomic.yacy.yacyVersion; import java.util.Map; import java.lang.StringBuffer; import java.util.Date; +import java.io.File; +import java.io.IOException; public class Threaddump_p { @@ -78,18 +82,18 @@ public class Threaddump_p { String versionstring = yacyVersion.combined2prettyVersion(sb.getConfig("version","0.1")); buffer.append("************* Start Thread Dump " + dt + " *******************").append("
"); - buffer.append("
YaCy Version: " + versionstring + "
"); + buffer.append("
YaCy Version: " + versionstring + "
"); buffer.append("Total Memory = " + (Runtime.getRuntime().totalMemory())).append("
"); buffer.append("Used  Memory = " + (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory())).append("
"); buffer.append("Free  Memory = " + (Runtime.getRuntime().freeMemory())).append("
"); buffer.append(" --- --- --- ---

"); - appendStackTraces(buffer, stackTraces, Thread.State.BLOCKED); - appendStackTraces(buffer, stackTraces, Thread.State.RUNNABLE); - appendStackTraces(buffer, stackTraces, Thread.State.TIMED_WAITING); - appendStackTraces(buffer, stackTraces, Thread.State.WAITING); - appendStackTraces(buffer, stackTraces, Thread.State.NEW); - appendStackTraces(buffer, stackTraces, Thread.State.TERMINATED); + appendStackTraces(sb.getRootPath(), buffer, stackTraces, Thread.State.BLOCKED); + appendStackTraces(sb.getRootPath(), buffer, stackTraces, Thread.State.RUNNABLE); + appendStackTraces(sb.getRootPath(), buffer, stackTraces, Thread.State.TIMED_WAITING); + appendStackTraces(sb.getRootPath(), buffer, stackTraces, Thread.State.WAITING); + appendStackTraces(sb.getRootPath(), buffer, stackTraces, Thread.State.NEW); + appendStackTraces(sb.getRootPath(), buffer, stackTraces, Thread.State.TERMINATED); buffer.append("************* End Thread Dump " + dt + " *******************").append("
"); @@ -101,19 +105,46 @@ public class Threaddump_p { return prop; // return from serverObjects respond() } - private static void appendStackTraces(StringBuffer buffer, Map stackTraces, Thread.State stateIn) { + private static void appendStackTraces(File rootPath, StringBuffer buffer, Map stackTraces, Thread.State stateIn) { buffer.append("THREADS WITH STATES: " + stateIn.toString()).append("
").append("
"); + File classPath = new File(rootPath, "source"); for (Thread thread: stackTraces.keySet()) { - StackTraceElement[] stackTraceElement = stackTraces.get(thread); + StackTraceElement[] stackTraceElements = stackTraces.get(thread); + StackTraceElement ste; + String line; if (stateIn.equals(thread.getState())) { buffer.append("Thread= " + thread.getName() + " " + (thread.isDaemon()?"daemon":"") + " id=" + thread.getId() + " " + thread.getState().toString()).append("
"); - for (int i = 0; i < stackTraceElement.length; i++) { - buffer.append("at " + htmlTools.encodeUnicode2html(stackTraceElement[i].toString(), true)).append("
"); + for (int i = 0; i < stackTraceElements.length; i++) { + ste = stackTraceElements[i]; + if (i == 0) { + line = getLine(classPath, ste.getClassName(), ste.getLineNumber()); + } else { + line = null; + } + if ((line != null) && (line.length() > 0)) { + buffer.append("at " + htmlTools.encodeUnicode2html(ste.toString(), true)).append(" [").append(line).append("]
"); + } else { + buffer.append("at " + htmlTools.encodeUnicode2html(ste.toString(), true)).append("
"); + } } buffer.append("
"); } } buffer.append("
"); } + + private static String getLine(File sourcePath, String classname, int line) { + // find class + String classPath = classname.replace('.', '/') + ".java"; + File file = new File(sourcePath, classPath); + if (!file.exists()) return ""; + try { + String lineString = nxTools.line(serverFileUtils.read(file), line); + if (lineString == null) return "@ERROR"; + return lineString; + } catch (IOException e) { + return "@EXCEPTION: " + e.getMessage(); + } + } } diff --git a/source/de/anomic/kelondro/kelondroRowCollection.java b/source/de/anomic/kelondro/kelondroRowCollection.java index cdd7fd754..99ab1c9d5 100644 --- a/source/de/anomic/kelondro/kelondroRowCollection.java +++ b/source/de/anomic/kelondro/kelondroRowCollection.java @@ -52,15 +52,12 @@ public class kelondroRowCollection { static final Integer dummy = new Integer(0); public static ExecutorService sortingthreadexecutor = null; - public static CompletionService sortingthreadcompletion = null; - + static { if (serverProcessor.useCPU > 1) { sortingthreadexecutor = Executors.newCachedThreadPool(); - sortingthreadcompletion = new ExecutorCompletionService(sortingthreadexecutor); } else { sortingthreadexecutor = null; - sortingthreadcompletion = null; } } @@ -486,6 +483,7 @@ public class kelondroRowCollection { int p = partition(0, this.chunkcount, this.sortBound, swapspace); if ((sortingthreadexecutor != null) && (!sortingthreadexecutor.isShutdown()) && (p > 50)) { // sort this using multi-threading + CompletionService sortingthreadcompletion = new ExecutorCompletionService(sortingthreadexecutor); Future part = sortingthreadcompletion.submit(new qsortthread(this, 0, p, 0)); qsort(p, this.chunkcount, 0, swapspace); try { diff --git a/source/de/anomic/tools/nxTools.java b/source/de/anomic/tools/nxTools.java index d9b11663a..b93047538 100644 --- a/source/de/anomic/tools/nxTools.java +++ b/source/de/anomic/tools/nxTools.java @@ -43,6 +43,10 @@ package de.anomic.tools; +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.LineNumberReader; import java.io.UnsupportedEncodingException; import java.util.ArrayList; import java.util.Enumeration; @@ -189,6 +193,21 @@ public class nxTools { return v; } + public static String line(byte[] a, int lineNr) { + InputStreamReader r = new InputStreamReader(new ByteArrayInputStream(a)); + LineNumberReader lnr = new LineNumberReader(r); + String theLine = null; + while (lnr.getLineNumber() < lineNr) { + try { + theLine = lnr.readLine(); + } catch (IOException e) { + return null; + } + if (theLine == null) return null; + } + return theLine; + } + /** * This function shorten URL Strings
*