Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 28th, 2012  |  syntax: None  |  size: 1.01 KB  |  hits: 17  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Log4j: is it synchronized for multithreaded calls?
  2. void someFunction()
  3. {
  4. Log.info("entered some function");
  5. ...
  6.  
  7. Log.info("existed some function");
  8. }
  9.        
  10. public void info(Object message) {
  11.     if(repository.isDisabled(Level.INFO_INT))
  12.        return;
  13.     if(Level.INFO.isGreaterOrEqual(this.getEffectiveLevel()))
  14.        forcedLog(FQCN, Level.INFO, message, null);
  15. }
  16.  
  17. ...
  18.  
  19. protected void forcedLog(String fqcn, Priority level, Object message, Throwable t) {
  20.     callAppenders(new LoggingEvent(fqcn, this, level, message, t));
  21. }
  22.  
  23. ...
  24.  
  25. public void callAppenders(LoggingEvent event) {
  26.     int writes = 0;
  27.  
  28.     for(Category c = this; c != null; c=c.parent) {
  29.         // Protected against simultaneous call to addAppender, removeAppender,...
  30.         synchronized(c) {
  31.             if(c.aai != null) {
  32.                 writes += c.aai.appendLoopOnAppenders(event);
  33.             }
  34.             if(!c.additive) {
  35.                 break;
  36.             }
  37.         }
  38.     }
  39.  
  40.     if(writes == 0) {
  41.         repository.emitNoAppenderWarning(this);
  42.     }
  43. }