Saturday, 7 January 2012

ActiveAsynchronousAppender Overhauled

I originally wrote the ActiveAsynchronousAppender back in 2008 as an alternative to the out-of-the-box Log4J AsyncAppender.  The reasons for having done so back then still hold today:
  • The AsyncAppender appends all events from its logging event buffer in a single loop before rechecking the buffer.  This can block the application if application threads are queueing for the buffer lock - behaviour somewhat similar to a GC pause.
  • The AsyncAppender fails to synchronous appending if a RuntimeException is encountered by its logging event dispatch thread.
The original incarnation of the ActiveAsynchronousAppender was designed for operation on Java 1.4 VMs.  It could also take advantage of the backport-util-concurrent if so configured.  There were some problems:
  • The original ActiveAsynchronousAppender depended upon the backport-util-concurrent in order to take advantage of newer concurrency features.  If you either didn’t want to or couldn’t put the backport-util-concurrent 3.1 JAR in your CLASSPATH, then the ActiveAsynchronousAppender was stuck with Java 1.4 synchronization.
  • It was unable to take advantage of the native concurrency APIs on Java 1.5 and higher VMs.
  • Due to a similarity with the AsyncAppender, the ActiveAsynchronousAppender shared a bug caused by LoggingEvents not having been fully rendered before being handed off to an attached Appender.
All of the above problems have been solved in the new version of the ActiveAsynchronousAppender.  Check it out at