You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by "Millard, Ray" <RM...@Aegonusa.com> on 2001/08/15 00:13:40 UTC

When to call NDC::remove

We are working in a J2EE Model II environment.  In various mail threads,
users have mentioned that there are several possible locations to call
NDC::remove, however, I haven't been able to find a thread that mentions
exactly where different organizations are calling it.  I have thought about
the following scenario:

1. In the doGet/doPost, call NDC.push("something unique about the user");
2. At the end of the doGet/doPost call NDC.pop();
3. In the servlet finalize method call NDC::remove.

I am not sure that this scenario will work to reclaim the memory, as I do
not know if the log4J framework holds a reference to the servlet and thus
prevents the finalize method from being called.  If you are using NDCs in a
Model II environment, please respond back with your NDC scenario.

Thanks!


---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: log4j-user-help@jakarta.apache.org


Re: When to call NDC::remove

Posted by Ceki Gülcü <cg...@qos.ch>.
Ray,

This is from the NDC javadoc:

Heavy duty systems should call the remove() method when leaving the run method of a thread. This ensures that the memory used by the thread can be freed by the Java garbage collector. There is a mechanism to lazily remove references to dead threads. In practice, this means that you can be a little sloppy and sometimes forget to call remove() before exiting a thread. 

The problem in your case is that you do not control the life cycle of the calling thread. Have you considered calling NDC remove at the end of the HTTP request? Regards, Ceki

ps: Interesting problem by the way.

At 17:13 14.08.2001 -0500, Millard, Ray wrote:
>We are working in a J2EE Model II environment.  In various mail threads,
>users have mentioned that there are several possible locations to call
>NDC::remove, however, I haven't been able to find a thread that mentions
>exactly where different organizations are calling it.  I have thought about
>the following scenario:
>
>1. In the doGet/doPost, call NDC.push("something unique about the user");
>2. At the end of the doGet/doPost call NDC.pop();
>3. In the servlet finalize method call NDC::remove.
>
>I am not sure that this scenario will work to reclaim the memory, as I do
>not know if the log4J framework holds a reference to the servlet and thus
>prevents the finalize method from being called.  If you are using NDCs in a
>Model II environment, please respond back with your NDC scenario.
>
>Thanks!

--
Ceki Gülcü - http://qos.ch


---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: log4j-user-help@jakarta.apache.org