- fixed a problem with thread pools in row collection

- added a line-viewing feature in threaddump	

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@4587 6c8d7289-2bf4-0310-a012-ef5d649a1542
pull/1/head
orbiter 17 years ago
parent e43051b125
commit 3e44293f07

@ -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("<br />");
buffer.append("<br /> YaCy Version: " + versionstring + "<br />");
buffer.append("<br /> YaCy Version: " + versionstring + "<br />");
buffer.append("Total Memory = " + (Runtime.getRuntime().totalMemory())).append("<br />");
buffer.append("Used&nbsp;&nbsp;Memory = " + (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory())).append("<br />");
buffer.append("Free&nbsp;&nbsp;Memory = " + (Runtime.getRuntime().freeMemory())).append("<br />");
buffer.append(" --- --- --- --- <br /><br />");
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("<br />");
@ -101,19 +105,46 @@ public class Threaddump_p {
return prop; // return from serverObjects respond()
}
private static void appendStackTraces(StringBuffer buffer, Map<Thread,StackTraceElement[]> stackTraces, Thread.State stateIn) {
private static void appendStackTraces(File rootPath, StringBuffer buffer, Map<Thread,StackTraceElement[]> stackTraces, Thread.State stateIn) {
buffer.append("THREADS WITH STATES: " + stateIn.toString()).append("<br />").append("<br />");
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("<br />");
for (int i = 0; i < stackTraceElement.length; i++) {
buffer.append("at " + htmlTools.encodeUnicode2html(stackTraceElement[i].toString(), true)).append("<br />");
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("]<br />");
} else {
buffer.append("at " + htmlTools.encodeUnicode2html(ste.toString(), true)).append("<br />");
}
}
buffer.append("<br />");
}
}
buffer.append("<br />");
}
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();
}
}
}

@ -52,15 +52,12 @@ public class kelondroRowCollection {
static final Integer dummy = new Integer(0);
public static ExecutorService sortingthreadexecutor = null;
public static CompletionService<Object> sortingthreadcompletion = null;
static {
if (serverProcessor.useCPU > 1) {
sortingthreadexecutor = Executors.newCachedThreadPool();
sortingthreadcompletion = new ExecutorCompletionService<Object>(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<Object> sortingthreadcompletion = new ExecutorCompletionService<Object>(sortingthreadexecutor);
Future<Object> part = sortingthreadcompletion.submit(new qsortthread(this, 0, p, 0));
qsort(p, this.chunkcount, 0, swapspace);
try {

@ -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<br>
*

Loading…
Cancel
Save