Improve thread naming and include thread ids in helma log message.

This commit is contained in:
hns 2008-10-16 14:30:47 +00:00
parent 3af404d39e
commit ee391ae6db
3 changed files with 14 additions and 6 deletions

View file

@ -342,7 +342,7 @@ public final class Application implements Runnable {
String ignoreDirs;
Initializer(String dirs) {
super("INIT-" + name);
super(name + "-init");
ignoreDirs = dirs;
}
@ -489,7 +489,7 @@ public final class Application implements Runnable {
releaseEvaluator(eval);
}
worker = new Thread(this, "Worker-" + name);
worker = new Thread(this, name + "-worker");
worker.setPriority(Thread.NORM_PRIORITY + 1);
worker.start();
}

View file

@ -79,6 +79,10 @@ public final class RequestEvaluator implements Runnable {
// the exception thrown by the evaluator, if any.
private volatile Exception exception;
// For numbering threads.
private int threadId;
/**
* Create a new RequestEvaluator for this application.
* @param app the application
@ -668,7 +672,7 @@ public final class RequestEvaluator implements Runnable {
if ((thread == null) || !thread.isAlive()) {
// app.logEvent ("Starting Thread");
thread = new Thread(app.threadgroup, this);
thread = new Thread(app.threadgroup, this, app.getName() + "-" + (++threadId));
thread.setContextClassLoader(app.getClassLoader());
thread.start();
} else {

View file

@ -143,7 +143,9 @@ public class Logger implements Log {
// has gone. the 2000 entries threshold is somewhat arbitrary.
if (entries.size() < 2000) {
String message = msg == null ? "null" : msg.toString();
entries.add(new Entry(dateCache, level, message, exception));
Thread thread = Thread.currentThread();
String threadId = "[" + thread.getName() + "] ";
entries.add(new Entry(dateCache, level, message, threadId, exception));
}
}
@ -164,6 +166,7 @@ public class Logger implements Log {
Entry entry = (Entry) entries.remove(0);
writer.print(entry.date);
writer.print(entry.level);
writer.print(entry.threadId);
writer.println(entry.message);
if (entry.exception != null)
entry.exception.printStackTrace(writer);
@ -294,13 +297,14 @@ public class Logger implements Log {
}
class Entry {
final String date, level, message;
final String date, level, message, threadId;
final Throwable exception;
Entry(String date, String level, String message, Throwable exception) {
Entry(String date, String level, String message, String threadId, Throwable exception) {
this.date = date;
this.level = level;
this.message = message;
this.threadId = threadId;
this.exception = exception;
}
}