On Thu, 2003-12-18 at 07:56, Ceki GÃlcà wrote:

> >class State {
> >    Logger log;
> >
> >    synchronized void setState() {
> >      // Something takes a long time here
> >      log.debug("hello world");
> >    }
> >
> >    synchronized Object getState() {
> >    }
> >
> >    public String toString() {
> >       return "state=" + getState();
> >    }
> >}
> 
> The above scenario is quite special. It is yet unclear if the deadlock 
> observed by Prithi is related.

Well, that's the sort of scenario that I have run into, under load while
having debugging on.  I have run into it under JBoss with the JBoss
classloader.  I have run into it in a open source library.  If you are
doing any sort of multi-threaded programming with logging under multiple
threads, I have been able to reproduce this deadlock every time.

If you don't plan to fix this issue, you should at least make a note
about the problem.

Here's a program which will reproduce the deadlock.  There is nothing
special about this program:

import org.apache.log4j.Logger;

public class Deadlock {

  static final Logger log = Logger.getLogger(Deadlock.class);
  String var;

  public synchronized void setVar(String var) {
    log.debug(this);
  }
  public synchronized String getVar() {
    return var;
  }
  public String toString() {
    return "Value x=" + getVar();
  }

  public static void main(String args[]) throws Exception {
    final Deadlock d = new Deadlock();
    new Thread() {
      public void run() {
        while (true) log.debug(d);
      }
    }.start();
    new Thread() {
      public void run() {
        while (true) d.setVar("n");
      }
    }.start();
  }
}                                                                                      
                

You also need this log4j.properties file:

# Log4j configuration for unit tests
log4j.rootCategory=debug, R

log4j.appender.R=org.apache.log4j.RollingFileAppender
log4j.appender.R.File=deadlock.log
log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern=%d [%t] %-5p (%C:%M) - %m%n




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to