You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by Milind Rao <mi...@bellsouth.net> on 2003/07/14 13:17:32 UTC

File locking in FileAppender

Is FileAppender thread safe?  I don't see any file locking occuring in the FileAppender & WriterAppender classes.

If I have 2 processes writing to the same log file, could I get a conflict?  
If I have 2 threads writing to the same log file, could I get a conflict?

I haven't been able to get a conflict, but that of course doesn't mean anything.  Threading problems are not that easy to 
simulate.

Category.callAppenders() locks on the category, but that shouldn't be doing anything for file locking.



Regards
Milind



---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: log4j-user-help@jakarta.apache.org


RE: File locking in FileAppender

Posted by Thomas Muller <tt...@online.no>.
Milin,

| Thanks for the quick response.  I don't see anything specifically
| written about file locking in the java.io.Writer.

Of course not. java.io.Writer is a generic (abstract) character emitter and
leaves the media specifics to the subclasses, such as FileWriter. I wanted
to draw your attention to how it enforces synchronization across concurrent
calls to the write operation, since you asked how WriterAppender implemented
concurrency control.

| FileOutputStream javadocs does say that
|     "Some platforms, in particular, allow a file to be opened for
| writing by only one FileOutputStream
|     (or other file-writing object) at a time. In such situations
| the constructors in this class will fail if the file
|     involved is already open."
|
| On Windows I can definitely open the same file for writing in 2
| processes.  There is no failure in the constructor.  So
| should I assume that there is no file locking on Windows?

No, but you can assume that the OS controls concurrent writes internally.

|  The
| "write" method is native as you said, but there is no
| documentation on the implementation.

Which is according to java's intention of being as close to platform
independent as possible.

--

Thomas





*************************************************************************
Copyright ERA Technology Ltd. 2003. (www.era.co.uk). All rights reserved. 
The information supplied in this Commercial Communication should be treated
in confidence.
No liability whatsoever is accepted for any loss or damage 
suffered as a result of accessing this message or any attachments.

________________________________________________________________________
This email has been scanned for all viruses by the MessageLabs Email
Security System. For more information on a proactive email security
service working around the clock, around the globe, visit
http://www.messagelabs.com
________________________________________________________________________

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: log4j-user-help@jakarta.apache.org


RE: File locking in FileAppender

Posted by Milind Rao <mi...@bellsouth.net>.
Thanks for the quick response.  I don't see anything specifically written about file locking in the java.io.Writer.

FileOutputStream javadocs does say that 
    "Some platforms, in particular, allow a file to be opened for writing by only one FileOutputStream 
    (or other file-writing object) at a time. In such situations the constructors in this class will fail if the file 
    involved is already open."

On Windows I can definitely open the same file for writing in 2 processes.  There is no failure in the constructor.  So 
should I assume that there is no file locking on Windows?  The "write" method is native as you said, but there is no 
documentation on the implementation.  

On Mon, 14 Jul 2003 12:49:30 +0100, Thomas Muller wrote:

>Milind,
>
>The appenders are indeed threadsafe. Consult java.io.Writer to learn how
>this class controls concurrent write operations. The FileOutputStream are
>implemented using native methods and uses OS specific file locks to enforce
>concorrency control.
>
>Hope this helps.
>
>--
>
>Thomas
>
>| -----Original Message-----
>| From: Milind Rao [mailto:milindr@bellsouth.net]
>| Sent: 14 July 2003 12:18
>| To: Log4J Users List
>| Subject: File locking in FileAppender
>|
>|
>| Is FileAppender thread safe?  I don't see any file locking
>| occuring in the FileAppender & WriterAppender classes.
>|
>| If I have 2 processes writing to the same log file, could I get a
>| conflict?
>| If I have 2 threads writing to the same log file, could I get a conflict?
>|
>| I haven't been able to get a conflict, but that of course doesn't
>| mean anything.  Threading problems are not that easy to
>| simulate.
>|
>| Category.callAppenders() locks on the category, but that
>| shouldn't be doing anything for file locking.
>|
>|
>|
>| Regards
>| Milind
>|
>|
>|
>| ---------------------------------------------------------------------
>| To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
>| For additional commands, e-mail: log4j-user-help@jakarta.apache.org
>|
>|
>
>
>
>*************************************************************************
>Copyright ERA Technology Ltd. 2003. (www.era.co.uk). All rights reserved. 
>The information supplied in this Commercial Communication should be treated
>in confidence.
>No liability whatsoever is accepted for any loss or damage 
>suffered as a result of accessing this message or any attachments.
>
>________________________________________________________________________
>This email has been scanned for all viruses by the MessageLabs Email
>Security System. For more information on a proactive email security
>service working around the clock, around the globe, visit
>http://www.messagelabs.com
>________________________________________________________________________
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: log4j-user-help@jakarta.apache.org
>



Regards
Milind



---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: log4j-user-help@jakarta.apache.org


RE: File locking in FileAppender

Posted by Thomas Muller <tt...@online.no>.
Milind,

The appenders are indeed threadsafe. Consult java.io.Writer to learn how
this class controls concurrent write operations. The FileOutputStream are
implemented using native methods and uses OS specific file locks to enforce
concorrency control.

Hope this helps.

--

Thomas

| -----Original Message-----
| From: Milind Rao [mailto:milindr@bellsouth.net]
| Sent: 14 July 2003 12:18
| To: Log4J Users List
| Subject: File locking in FileAppender
|
|
| Is FileAppender thread safe?  I don't see any file locking
| occuring in the FileAppender & WriterAppender classes.
|
| If I have 2 processes writing to the same log file, could I get a
| conflict?
| If I have 2 threads writing to the same log file, could I get a conflict?
|
| I haven't been able to get a conflict, but that of course doesn't
| mean anything.  Threading problems are not that easy to
| simulate.
|
| Category.callAppenders() locks on the category, but that
| shouldn't be doing anything for file locking.
|
|
|
| Regards
| Milind
|
|
|
| ---------------------------------------------------------------------
| To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
| For additional commands, e-mail: log4j-user-help@jakarta.apache.org
|
|



*************************************************************************
Copyright ERA Technology Ltd. 2003. (www.era.co.uk). All rights reserved. 
The information supplied in this Commercial Communication should be treated
in confidence.
No liability whatsoever is accepted for any loss or damage 
suffered as a result of accessing this message or any attachments.

________________________________________________________________________
This email has been scanned for all viruses by the MessageLabs Email
Security System. For more information on a proactive email security
service working around the clock, around the globe, visit
http://www.messagelabs.com
________________________________________________________________________

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: log4j-user-help@jakarta.apache.org