You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-dev@logging.apache.org by Michael Miloslavski <mm...@hotmail.com> on 2001/02/06 10:09:14 UTC

No synchronization in SMTPAppender?

 Hello, 
 I looked through the code of the SMTPAppender, and it seems like there is no synchronization their. For example, in the append() method, adding element to the CyclicBuffer is not synchronized. CyclicBuffer itself has no internal synchronization either. 

 Michael



Re: No synchronization in SMTPAppender?

Posted by Ceki Gülcü <cg...@urbanet.ch>.
Hi Michael,

That is correct. However, AppenderSkeleton.doAppend is synchronized which prevents simultaneous access to CyclicBuffer. Thus, SMTPAppender is safe even in a multi-threaded environment. 

The configuration related methods such as setOption, activateOptions etc. are not synchronized either. This is deemed safe because the PropertyConfigurator and the DOMConfigurator act on new instances of appenders and these appenders are available only after they are configured because the category where they are attached to is synchronized during configuration. A locked category cannot log due to the synchronization in the Category.callAppenders method.  

However, before creating and configuring the new appender instance, these configurators close all attached appenders to a category mentioned in the config file. One possible bug is that a configurator closes an appender while the appender is in the middle of an append operation. See http://nagoya.betaversion.org/bugzilla/show_bug.cgi?id=509 for an example.  The solution is to have the close method in appenders as synchronized.


I think the assumptions made about how appenders are accessed and configured should be better documented. The fact of the matter is that appenders are thread-safe (with the exception of bug 509) even if they are not synchronized all over the place. I hope this clarifies the matter. Ceki
 

At 10:09 06.02.2001 +0100, you wrote:
> Hello, 
>
> I looked through the code of the SMTPAppender, and it seems like there is no synchronization their. For example, in the append() method, adding element to the CyclicBuffer is not synchronized. CyclicBuffer itself has no internal synchronization either. 
>
> Michael
> 

----
Ceki Gülcü           e-mail: cgu@urbanet.ch (preferred)
av. de Rumine 5              ceki_gulcu@yahoo.com
CH-1005 Lausanne          
Switzerland            Tel: ++41 21 351 23 15