私は次のような状況にあります:
- いくつかの静的なクラスを持つ共通ライブラリ (組織によって作成された) があり (最適化のためにメモリ内に多くのレコードがあるため)、Tomcat の lib ディレクトリにデプロイされます (デプロイされたすべての webapps にアクセスするため)。
- 静的クラスは DB 接続にアクセスする必要があり、そのために (問題があれば) log4j を使用しますが、そのアプローチでは次の問題が発生します。
log4j:WARN ロガー (dev.sample.test.TestLog4J) のアペンダーが見つかりませんでした。log4j:WARN log4j システムを適切に初期化してください。
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"]
この問題は、 https ://wiki.apache.org/commons/Logging/StaticLog で十分に文書化されていますが、この問題に対する明確な修正はありません (Tomcat サーバーの logging.properties ファイルの構成など)。
ログを記録する Java クラスのコードは非常に単純です。
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);
}
}
}
それで、選択肢は何ですか?System.out.println(...) で「ロギング」を行うのは少し見苦しいので、log4j を使用してこの問題を回避できることを願っています。
よろしく、そしてあなたの答えにthx :)