On 17/11/2009, fha...@apache.org <fha...@apache.org> wrote:
> Author: fhanik
>  Date: Tue Nov 17 17:35:57 2009
>  New Revision: 881396
>
>  URL: http://svn.apache.org/viewvc?rev=881396&view=rev
>  Log:
>  Make the file handler thread safe

If only - there are several other mutable instance fields that are not
synchronized.

AFAICT access to the PrintWriter is not thread-safe - for example, the
openWriter() method has a window whereby the publish() method can
write a log record before the header has been written.

>
>  Modified:
>     tomcat/trunk/java/org/apache/juli/FileHandler.java
>
>  Modified: tomcat/trunk/java/org/apache/juli/FileHandler.java
>  URL: 
> http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/juli/FileHandler.java?rev=881396&r1=881395&r2=881396&view=diff
>  
> ==============================================================================
>  --- tomcat/trunk/java/org/apache/juli/FileHandler.java (original)
>  +++ tomcat/trunk/java/org/apache/juli/FileHandler.java Tue Nov 17 17:35:57 
> 2009
>  @@ -95,7 +95,7 @@
>      /**
>       * 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 @@
>          }
>
>          try {
>  +            PrintWriter writer = this.writer;
>              if (writer!=null) {
>                  writer.write(result);
>              } else {
>  @@ -170,6 +171,8 @@
>      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 void flush() {
>
>          try {
>  +            PrintWriter writer = this.writer;
>  +            if (writer==null)
>  +                return;
>              writer.flush();
>          } catch (Exception e) {
>              reportError(null, e, ErrorManager.FLUSH_FAILURE);
>
>
>
>  ---------------------------------------------------------------------
>  To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
>  For additional commands, e-mail: dev-h...@tomcat.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to