i have the following situation:
- We have a common library (made by our organization) that have some class that is static (because for optimization have many records in memory) and it's deployed in the lib directory of the tomcat (to be accesed to all webapps deployed).
- The static class need to access to DB conection, and for that (if there any problem) we use log4j, but that aproach generate the following problem:
log4j:WARN No appenders could be found for logger (dev.sample.test.TestLog4J). log4j:WARN Please initialize the log4j system properly.
And also when the server is stop, there are some memory leaks in the webapps that load (or use) the static class:
Jul 24, 2014 11:29:34 AM org.apache.catalina.core.StandardContext reload
INFO: Reloading Context with name [/fake_smsc] has started
Jul 24, 2014 11:29:34 AM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
SEVERE: The web application [/fake_smsc] appears to have started a thread named [MultiThreadedHttpConnectionManager cleanup] but has failed to stop it. This is very likely to create a memory leak.
Jul 24, 2014 11:29:34 AM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
SEVERE: The web application [/fake_smsc] appears to have started a thread named [Timer-2] but has failed to stop it. This is very likely to create a memory leak.
Jul 24, 2014 11:29:34 AM org.apache.catalina.loader.WebappClassLoader checkThreadLocalMapForLeaks
SEVERE: The web application [/fake_smsc] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@65686a12]) and a value of type [org.mockito.configuration.DefaultMockitoConfiguration] (value [org.mockito.configuration.DefaultMockitoConfiguration@2a0bf7c1]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
Jul 24, 2014 11:29:34 AM org.apache.catalina.loader.WebappClassLoader checkThreadLocalMapForLeaks
SEVERE: The web application [/fake_smsc] created a ThreadLocal with key of type [com.google.gson.Gson$1] (value [com.google.gson.Gson$1@7c43d507]) and a value of type [java.util.HashMap] (value [{}]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
Jul 24, 2014 11:29:34 AM org.apache.catalina.loader.WebappClassLoader checkThreadLocalMapForLeaks
SEVERE: The web application [/fake_smsc] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@4956fe4d]) and a value of type [org.mockito.internal.progress.MockingProgressImpl] (value [iOngoingStubbing: org.mockito.internal.stubbing.OngoingStubbingImpl@6e5196d8, verificationMode: null, stubbingInProgress: null]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
Jul 24, 2014 11:29:35 AM org.apache.catalina.core.StandardContext reload
INFO: Reloading Context with name [/fake_smsc] is completed
Jul 24, 2014 11:29:43 AM org.apache.catalina.core.StandardServer await
INFO: A valid shutdown command was received via the shutdown port. Stopping the Server instance.
Jul 24, 2014 11:29:43 AM org.apache.coyote.AbstractProtocol pause
INFO: Pausing ProtocolHandler ["http-bio-9191"]
Jul 24, 2014 11:29:43 AM org.apache.coyote.AbstractProtocol pause
INFO: Pausing ProtocolHandler ["ajp-bio-9109"]
Jul 24, 2014 11:29:43 AM org.apache.catalina.core.StandardService stopInternal
INFO: Stopping service Catalina
Jul 24, 2014 11:29:44 AM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
SEVERE: The web application [/sms_services] appears to have started a thread named [MultiThreadedHttpConnectionManager cleanup] but has failed to stop it. This is very likely to create a memory leak.
Jul 24, 2014 11:29:44 AM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
SEVERE: The web application [/sms_services] appears to have started a thread named [ActiveMQ Connection Executor: vm://localhost#2] but has failed to stop it. This is very likely to create a memory leak.
Jul 24, 2014 11:29:44 AM org.apache.coyote.AbstractProtocol stop
INFO: Stopping ProtocolHandler ["http-bio-9191"]
Jul 24, 2014 11:29:44 AM org.apache.coyote.AbstractProtocol stop
INFO: Stopping ProtocolHandler ["ajp-bio-9109"]
Jul 24, 2014 11:29:44 AM org.apache.coyote.AbstractProtocol destroy
INFO: Destroying ProtocolHandler ["http-bio-9191"]
Jul 24, 2014 11:29:44 AM org.apache.coyote.AbstractProtocol destroy
INFO: Destroying ProtocolHandler ["ajp-bio-9109"]
This problem it's well documented at: https://wiki.apache.org/commons/Logging/StaticLog but don't have a clean fix to this problem (like some configuration in the logging.properties file of the tomcat server)
The code of the java class that is logging is very simple:
public class TestLog4J {
private static Logger log = Logger.getLogger(TestLog4J.class);
static {
log.debug("We created the instance of the Test class.");
try {
//Do black magic connecting to the db
connectDatabase();
} catch (Exception e) {
log.error("What a Terrible Failure (WTF): ", e);
}
}
}
So, what are the choices? It's seem a little ugly do the "logging" with System.out.println(...), so i hope that maybe are some work around to this problem using log4j.
Regards, and thx for your's answers :)