Bug 51048 - AsyncAppender.doAppend() does not need to be synchronized
Summary: AsyncAppender.doAppend() does not need to be synchronized
Status: NEW
Alias: None
Product: Log4j - Now in Jira
Classification: Unclassified
Component: Appender (show other bugs)
Version: 1.2
Hardware: PC Windows XP
: P2 normal
Target Milestone: ---
Assignee: log4j-dev
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-04-11 07:38 UTC by Bartek Kowalewski
Modified: 2011-04-26 18:42 UTC (History)
1 user (show)



Attachments
A subclass of AsyncAppender that removes the unneeded synchronization (901 bytes, text/x-java)
2011-04-11 07:39 UTC, Bartek Kowalewski
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Bartek Kowalewski 2011-04-11 07:38:00 UTC
The AppenderSkeleton class defines the 'public synchronized void doAppend(LoggingEvent event)' method. Making this method non synchronized directly in AppenderSkeleton isn't safe as there are might be plenty of (custom 3rd party) subclasses that might take advantage of this synchronization. 

However, some widely used _concrete_ appenders that are defined inside the log4j library could be optimized. The AsyncAppender class seems to be the most often used appender in enterprise class systems. Making the doAppend() method non synchronized in this case makes a lot of sense as checking if level is lower than threshold is done in doAppend(). This change would improve log4j behavior in multi-threaded environments.

AsyncAppender is anyway internally synchronized - it synchronizes on the buffer field.

Attaching a subclass of AsyncAppender that removes the unnecessary 'synchronized' keyword.
Comment 1 Bartek Kowalewski 2011-04-11 07:39:23 UTC
Created attachment 26872 [details]
A subclass of AsyncAppender that removes the unneeded synchronization