Log4j deadlock occuring between Logger and Appender?

I saw a similar trace today in my own code. Maybe it applies to you too?

I saw a similar trace today in my own code. Maybe it applies to you too? Summary: Before (deadlock): logger.Info(x); (where x is a complicated object that acquires a read lock within toString()) After (ok): logger.

Info(x.toString()); Details: In one thread I called logger. Info(x), which called Category. CallAppenders(LoggingEvent), which synchronizes on an appender and then calls x.toString(), which tried to acquire a read lock on x and blocked.

In another thread, I had a method that held the write lock on x while calling logger. Info(""), which also called callAppenders, tried to synchronize on an appender, and blocked. Here's the relevant part of the trace: Thread One WAITING sun.misc.Unsafe.

Park(native method) java.util.concurrent.locks.LockSupport. Park(LockSupport. Java:158) java.util.concurrent.locks.

AbstractQueuedSynchronizer. ParkAndCheckInterrupt(AbstractQueuedSynchronizer. Java:811) java.util.concurrent.locks.

AbstractQueuedSynchronizer. DoAcquireShared(AbstractQueuedSynchronizer. Java:941) java.util.concurrent.locks.

AbstractQueuedSynchronizer. AcquireShared(AbstractQueuedSynchronizer. Java:1261) (... my ReadWriteLock$ReadLock.

Lock(Lock. Java:256)) (... my Object's toString() ...) org.apache. Log4j.or.DefaultRenderer.

DoRender(DefaultRenderer. Java:36) org.apache. Log4j.or.RendererMap.

FindAndRender(RendererMap. Java:80) org.apache. Log4j.spi.LoggingEvent.

GetRenderedMessage(LoggingEvent. Java:362) org.apache. Log4j.xml.XMLLayout.

Format(XMLLayout. Java:148) org.apache. Log4j.WriterAppender.

SubAppend(WriterAppender. Java:302) org.apache. Log4j.WriterAppender.

Append(WriterAppender. Java:160) org.apache. Log4j.

AppenderSkeleton. DoAppend(AppenderSkeleton. Java:251) org.apache.

Log4j.helpers. AppenderAttachableImpl. AppendLoopOnAppenders(AppenderAttachableImpl.

Java:66) org.apache. Log4j.Category. CallAppenders(Category.

Java:206) org.apache. Log4j.Category. ForcedLog(Category.

Java:391) org.apache. Log4j.Category. Log(Category.

Java:856) Log. Ndebug(Log. Java:965) Thread Two BLOCKED; waiting to lock org.apache.

Log4j. Logger@1623f org.apache. Log4j.Category.

CallAppenders(Category. Java:204) org.apache. Log4j.Category.

ForcedLog(Category. Java:391) org.apache. Log4j.Category.

Log(Category. Java:856) Log. Debug(Log.

Java:820) (.. something that acquires my reentrant ReadWriteLock$WriteLock ...).

– Neeraj Sep 13 at 7:06 Yes. My code was causing a deadlock because logger.Info(x) called x.toString() which acquired my own lock, and another thread that held my own lock called logger. Info("").

– yonran Sep 13 at 18:18.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions