2013/5/19 Nick Williams <nicho...@nicholaswilliams.net>:
>
> On May 19, 2013, at 10:01 AM, Caldarale, Charles R wrote:
>
>>> From: Nick Williams [mailto:nicho...@nicholaswilliams.net]
>>> Subject: Re: LOG4J2-223: IllegalStateException thrown during Tomcat 
>>> shutdown (memory leak, it looks like)
>>
>>> Log4j 1 never required a listener to be configured to be shut down
>>> properly when an application is undeployed.

It did.
E.g. this discussion is from March 2004:
https://issues.apache.org/bugzilla/show_bug.cgi?id=26372#c2

>>
>> What bearing does that have on a different logging mechanism?
>
> To be fair, Log4j 2 is not a different logging mechanism. It is a new version 
> of Log4j 1. My point was mostly philosophical; it "feels wrong" to have to 
> configure a listener just to support logging.


You can configure the listener from within a library either
a) by providing a javax.servlet.ServletContainerInitializer (starting
with Servlet 3.0) or
b) by configuring it in a TLD file of a tag library (starting with JSP 1.2).


>>
>>> It should be possible to do this without a listener.
>>
>> Not easily.
>>
>>> Could a `finalize` method be used instead of a shutdown hook/listener?
>>
>> Finalizers should be avoided like the plague.  The gyrations the JVM has to 
>> go through to handle them result in continual run time impacts, and require 
>> at least two GC passes to actually get rid of the objects.
>
> The extra performance impact is bad, yes, when you're talking about an object 
> who has many short-lived instances in memory that could be garbage collected 
> regularly. However, when you're talking about a lone singleton instance that 
> is created when the application starts and garbage collected when the 
> application shuts down, I would argue this is not a problem at all. Of 
> course, I'm open to the idea that I could be proven wrong.
>
>>
>>> What I don't know is if it is guaranteed to be called in non-web 
>>> applications
>>> when the JVM just shuts down.
>>
>> Finalizers are not called at JVM termination, since the process exit is 
>> expected to release resources automatically.  You cannot actually count on a 
>> finalizer ever being invoked; it's one of those "seemed like a good idea at 
>> the time" things that is now widely regretted by JVM implementers.
>
> After some experimentation, it would appear that it's not so much that 
> finalizers are not called at JVM termination as it is that finalizers are not 
> called if the garbage collector never runs, and the garbage collector isn't 
> guaranteed to run at JVM shutdown.

There exists such API as JVM shutdown hooks. An issue with them though
is that if there are several hooks, then all of them are started at
the same time and run in parallel.

When Tomcat is run with JULI it takes care of JULI shutdown (a)
disables JULI's own shutdown hook via
ClassLoaderLogManager.setUseShutdownHook(false), b) shuts down JULI
from its own shutdown hook thread).

Best regards,
Konstantin Kolinko

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org

Reply via email to