我正在使用线程本地方法为每个应用程序线程创建一个 json 序列化程序,以避免每次我想序列化它时创建对象。
我正在使用以下代码的代码:
public class JsonSerializerFactory {
private static final ThreadLocal<JsonSerializer> JSON_SERIALIZER =
new ThreadLocal<JsonSerializer>() {
@Override
protected JsonSerializer initialValue() {
return new JsonSerializer();
}
};
public static JsonSerializer get() {
return JSON_SERIALIZER;
}
}
每次我想获得序列化程序时,我都会这样做:
JsonSerializerFactory.get()
当我关闭tomcat时,我看到以下日志:
May 23, 2012 9:15:25 AM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads SEVERE: The web application [] appears to have started a thread named [Logback AsyncAppender Dispatcher [Async_Logger] - Thread-16] but has failed to stop it. This is very likely to create a memory leak.
我已经阅读了Tomcat 内存泄漏保护,但我可能在那里遗漏了一些东西。我真的有泄漏,还是应该忽略此消息?
有人可以解释一下吗?