Make the file handler thread safe
authorfhanik <fhanik@13f79535-47bb-0310-9956-ffa450edef68>
Tue, 17 Nov 2009 17:35:57 +0000 (17:35 +0000)
committerfhanik <fhanik@13f79535-47bb-0310-9956-ffa450edef68>
Tue, 17 Nov 2009 17:35:57 +0000 (17:35 +0000)
git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@881396 13f79535-47bb-0310-9956-ffa450edef68

java/org/apache/juli/FileHandler.java

index fed3252..964722b 100644 (file)
@@ -95,7 +95,7 @@ public class FileHandler
     /**
      * The PrintWriter to which we are currently logging, if any.
      */
-    private PrintWriter writer = null;
+    private volatile PrintWriter writer = null;
     
     /**
      * Log buffer size
@@ -143,6 +143,7 @@ public class FileHandler
         }
         
         try {
+            PrintWriter writer = this.writer;
             if (writer!=null) {
                 writer.write(result);
             } else {
@@ -170,6 +171,8 @@ public class FileHandler
     protected void closeWriter() {
         
         try {
+            PrintWriter writer = this.writer;
+            this.writer = null;
             if (writer == null)
                 return;
             writer.write(getFormatter().getTail(this));
@@ -191,6 +194,9 @@ public class FileHandler
     public void flush() {
 
         try {
+            PrintWriter writer = this.writer;
+            if (writer==null)
+                return;
             writer.flush();
         } catch (Exception e) {
             reportError(null, e, ErrorManager.FLUSH_FAILURE);