logging-log4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "E. Epstein (ML)" <mailing-l...@prajnait.com>
Subject NDC implementation log4j-1.2.8
Date Wed, 27 Oct 2004 19:01:14 GMT
Hi Ceki, et. al.:

I think this belongs here, in the developers list.  If, however, you
decide it does not and should instead be posted in the user list, please
accept my apologies in advance and just let me know and I'll repost

We have a system using NDC that kicks off threads to perform various
functions asynchronously.  When all goes well the threads exit and
before doing so call the NDC.remove() method as per the docs.  This is a
hybrid Java / JavaScript system so the problem comes in the JS code
where Rhino has control.  We cannot guarantee that if the thread dies
violently that we'll get a chance at cleanup!  We're concerned about
leaking memory via this dead threads.... OK, that's the motivation, now
for the part of this message that is dev related.

Digging into the NDC.java class I noticed that the issue seems to
revolve around the use of a Hashtable to store associated the nested
diagnostic contexts with their respective threads.  I'm wondering if a
ThreadLocal wouldn't work just as well and skirt the issue of retaining
references to threads via the Hashtable.  In addition I think it would
offer a nice performance boost.  Looking at the comments in
"lazyRemove()"  I found this comment:
      // The synchronization on ht is necessary to prevent JDK 1.2.x from
      // throwing ConcurrentModificationExceptions at us. This sucks
      // One solution is to write our own hashtable implementation.
The ThreadLocal class and its standard pattern remove this issue as
well.  They'd also remove the need for the package-private pushCounter ivar.

I'd like to code this up using ThreadLocal but wanted to not if
someone's already about to do so -- or has done so and its in CVS (sorry
I didn't check, I just took the latest release: 1.2.8).  Also, I noticed
that both static variables: Hashtable ht and int pushCounter are
declared package private rather than class private, and although I
searched the source tree and couldn't find any reference to NDC.ht or
NDC.pushCounter, I didn't want to see something break just because I
didn't find a reference when in fact there is one.

Thanks for staying with me for this lengthy post.  So.... having not
contributed to log4j before, what step next?  Should I just submit a
ThreadLocal version of the file?


= Ezra E.

P.S., Since writing this I've gone ahead and changed NDC.java.  It
compiles and passes basic tests.  It is gzipped and attached here.

View raw message