Friday, December 18, 2009

log4j: always use additivity=false

the logging code synchronizes on each category; you waste a lot of time - and risk to create serious contention - if you let every category to bubble up to "root".


Category.callAppenders :

  public void callAppenders(LoggingEvent event)   {
    int writes = 0;


    for (Category c = this; c != null; c = c.parent)    {
      synchronized (c) {
        if (c.aai != null)
          writes += c.aai.appendLoopOnAppenders(event);


        if (!(c.additive)) {
          monitorexit; break label67:
        }
      }
    }


    if (writes == 0)
      label67: this.repository.emitNoAppenderWarning(this);
  }


 (thanks to Fabien for this finding)



No comments: