remm 2005/02/08 04:21:18 Modified: util/java/org/apache/tomcat/util/log SystemLogHandler.java jasper2/src/share/org/apache/jasper/util SystemLogHandler.java Log: - 33368: fix leak in swallowOutput. - Submitted by Rainer Jung. - I still don't know the purpose of the stack which is used in one of the swallow output. Revision Changes Path 1.6 +14 -13 jakarta-tomcat-connectors/util/java/org/apache/tomcat/util/log/SystemLogHandler.java Index: SystemLogHandler.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-connectors/util/java/org/apache/tomcat/util/log/SystemLogHandler.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- SystemLogHandler.java 2 Sep 2004 18:48:47 -0000 1.5 +++ SystemLogHandler.java 8 Feb 2005 12:21:18 -0000 1.6 @@ -18,7 +18,7 @@ import java.io.IOException; import java.io.PrintStream; -import java.util.Hashtable; +import java.util.EmptyStackException; import java.util.Stack; /** @@ -58,7 +58,7 @@ /** * Thread <-> CaptureLog associations. */ - protected static Hashtable logs = new Hashtable(); + protected static ThreadLocal logs = new ThreadLocal(); /** @@ -75,19 +75,20 @@ */ public static void startCapture() { CaptureLog log = null; - - // Synchronized for Bugzilla 31018 - synchronized(reuse) { - log = reuse.isEmpty() ? new CaptureLog() : (CaptureLog)reuse.pop(); + if (!reuse.isEmpty()) { + try { + log = (CaptureLog)reuse.pop(); + } catch (EmptyStackException e) { + log = new CaptureLog(); + } + } else { + log = new CaptureLog(); } - - Thread thread = Thread.currentThread(); - Stack stack = (Stack)logs.get(thread); + Stack stack = (Stack)logs.get(); if (stack == null) { stack = new Stack(); - logs.put(thread, stack); + logs.set(stack); } - stack.push(log); } @@ -96,7 +97,7 @@ * Stop capturing thread's output and return captured data as a String. */ public static String stopCapture() { - Stack stack = (Stack)logs.get(Thread.currentThread()); + Stack stack = (Stack)logs.get(); if (stack == null || stack.isEmpty()) { return null; } @@ -118,7 +119,7 @@ * Find PrintStream to which the output must be written to. */ protected PrintStream findStream() { - Stack stack = (Stack)logs.get(Thread.currentThread()); + Stack stack = (Stack)logs.get(); if (stack != null && !stack.isEmpty()) { CaptureLog log = (CaptureLog)stack.peek(); if (log != null) { 1.5 +8 -10 jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/util/SystemLogHandler.java Index: SystemLogHandler.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/util/SystemLogHandler.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- SystemLogHandler.java 17 Mar 2004 19:23:05 -0000 1.4 +++ SystemLogHandler.java 8 Feb 2005 12:21:18 -0000 1.5 @@ -19,7 +19,6 @@ import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.PrintStream; -import java.util.Hashtable; /** @@ -55,13 +54,13 @@ /** * Thread <-> PrintStream associations. */ - protected static Hashtable streams = new Hashtable(); + protected static ThreadLocal streams = new ThreadLocal(); /** * Thread <-> ByteArrayOutputStream associations. */ - protected static Hashtable data = new Hashtable(); + protected static ThreadLocal data = new ThreadLocal(); // --------------------------------------------------------- Public Methods @@ -76,9 +75,8 @@ */ public static void setThread() { ByteArrayOutputStream baos = new ByteArrayOutputStream(); - PrintStream ps = new PrintStream(baos); - data.put(Thread.currentThread(), baos); - streams.put(Thread.currentThread(), ps); + data.set(baos); + streams.set(new PrintStream(baos)); } @@ -87,12 +85,12 @@ */ public static String unsetThread() { ByteArrayOutputStream baos = - (ByteArrayOutputStream) data.get(Thread.currentThread()); + (ByteArrayOutputStream) data.get(); if (baos == null) { return null; } - streams.remove(Thread.currentThread()); - data.remove(Thread.currentThread()); + streams.set(null); + data.set(null); return baos.toString(); } @@ -104,7 +102,7 @@ * Find PrintStream to which the output must be written to. */ protected PrintStream findStream() { - PrintStream ps = (PrintStream) streams.get(Thread.currentThread()); + PrintStream ps = (PrintStream) streams.get(); if (ps == null) { ps = wrapped; }
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]