我们使用 Apache Avro 作为 Python 应用程序和我们在 Tomcat 服务中运行的一些第三方 Java 库之间的 JSON 接口。我们决定简单地扩展 org.apache.avro.ipc.ResponderServlet 类来实现我们自己的 servlet。servlet 非常简单,因为它在构造函数中实例化了 ResponderServlet 超类,并重写了 init() 和 destroy() 方法来为我们在 servlet 中运行的第三方库做一些内务处理。
然而,当 Tomcat 取消部署我们的 web 应用程序时,我们会看到许多严重错误警告,警告 ThreadLocal 相关的内存泄漏。
SEVERE: The web application [/hotwire] created a ThreadLocal with key of type [org.apache.avro.Schema$3] (value [org.apache.avro.Schema$3@4464784f]) and a value of type [java.lang.Boolean] (value [true]) 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.
Jan 24, 2013 2:19:36 AM org.apache.catalina.loader.WebappClassLoader checkThreadLocalMapForLeaks
SEVERE: The web application [/hotwire] created a ThreadLocal with key of type [org.apache.avro.generic.GenericDatumReader$1] (value [org.apache.avro.generic.GenericDatumReader$1@2016ad9d]) and a value of type [org.apache.avro.util.WeakIdentityHashMap] (value [org.apache.avro.util.WeakIdentityHashMap@30e02ee0]) 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.
我们可能在某处做一些幼稚的事情,因为我们无法在网络上的任何地方为这种情况找到任何帮助。尽管如此,我们希望这里有人能告诉我们哪里出了问题。
这是对我们的 servlet 的一瞥。
public class HotWire extends ResponderServlet{
public HotWire() throws IOException
{
super(new SpecificResponder(Engine.class, new EngineImpl()));
}
@Override
public void init() {
try {
super.init();
try {
init_engine();
} catch (EngineInitException e) {
e.printStackTrace();
}
} catch (ServletException e) {
e.printStackTrace();
}
}
@Override
public void destroy() {
super.destroy();
shutdown_engine();
}
public static class EngineImpl implements EngineInterface {
public Boolean create(Parameters message) {
Boolean status = null;
try {
status = engine.create_object(message);
} catch (SemanticException | IOException e) {
e.printStackTrace();
}
return status;
}
}