On Wed, May 30, 2012 at 8:36 AM, Christian Grobmeier <[email protected]> wrote: > On Wed, May 30, 2012 at 7:59 AM, Ralph Goers <[email protected]> > wrote: >> As I see it, the problem is that at least some of the users seem to be >> expecting Log4j to magically know when to call clear. It can't. The >> application has to do it. >> >> All the MDC is is a ThreadLocal where each Thread has its own Map associated >> with the ThreadLocal. You can get and put all you want. In a webapp, of >> course, if you add stuff to the MDC at the beginning of a request then you >> need to remove it all at the end of the request. The normal pattern is >> >> MDC.put(key, value); >> try { >> call servlet >> } finally { >> MDC.remove(key); >> } >> >> The problem with this is that it still leaves an empty Map in the >> ThreadLocal. So when remove() removes the last element from the Map then the >> Map is removed from the ThreadLocal. > > OK understood. But actually isn't this happening with this fix? > in remove0(key): if table isEmpty -> call clear0() > In clear(): tlm.remove > > From what I understood now we are doing what we can do. Except, we can > provide a FAQ description.
Addendum: It seem the Servlet.destroy() Method is the place to clear the MDC. http://docs.oracle.com/javaee/6/api/javax/servlet/Servlet.html#destroy() "This method gives the servlet an opportunity to clean up any resources that are being held (for example, memory, file handles, threads)" --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
