All,
I was recently thinking about adding some NDC logging to my servlet, but I was concerned (perhaps unnecessarily) by some of the things I read in the docs and the source code.
Since I am in a servlet container I am not in control of my threads. So it is difficult to know when to call NDC.remove(). It seemed like it would be safe to call at the end of every request.
The servlet containers will usually pool threads. So NDC.remove should not be an issue. In any case, you can get by even if you invoke NDC.remove once every 1000 (one thousand) requests. The requirement is to call NDC.remove once in a while, that's all.
However, when I was looking over the implementation, I was concerned that it may be a performance issue, especially if there are a lot of requests and threads. I can see that whoever wrote the code was concerned as well. (In particular I am thinking of the comment concerning the synchronization of the ht variable.)
Yes, the ht synchronization is not very nice.
I think that the NDC class could be much improved through the use of the ThreadLocal class. I just checked the docs and ThreadLocal has been available since JDK 1.2; if I'm not mistaken that is the threshold we are working for?
Correct. We are aiming for JDK 1.2 compatibility.
Before I put any serious effort forward I wanted to make sure that such a change would fit in in terms of the overall vision and that I'm not missing something else that would prevent it being accepted. If one of the committers could confirm that it seems like a good idea, I'll start working on it.
Please do. You can take the MDC code as example. (For MDC code, use the latest from CVS not the code from 1.2.8). Test cases would be highly welcome.
Thanks, Ray
-- Ceki Gülcü
For log4j documentation consider "The complete log4j manual"
ISBN: 2970036908 http://www.qos.ch/shop/products/clm_t.jsp
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]