[英]Tomcat not unloading classes when aws s3 client is used
I am seeing a strange problem when using JAVA AWS s3 client. 使用JAVA AWS s3客户端时出现一个奇怪的问题。 When I make multiple deployments(tomcat is not restarted, just war files are updated), the heap size remains the same but non heap size keeps on increasing.
当我进行多个部署时(tomcat不重新启动,只是war文件被更新),堆大小保持不变,但非堆大小不断增加。 Turns out the classes are not unloaded when the application is undeployed.
原来,取消部署应用程序时不会卸载这些类。
My application has a simple context listener, which initialises an AWS S3 client and shuts it down when the application context is destroyed. 我的应用程序具有一个简单的上下文侦听器,该侦听器将初始化一个AWS S3客户端,并在销毁应用程序上下文时将其关闭。
Here is the code: 这是代码:
@WebListener
public class ContainerContextClosedHandler implements ServletContextListener {
private static AmazonS3 s3Client;
@Override
public void contextInitialized(ServletContextEvent servletContextEvent) {
s3Client = AmazonS3ClientBuilder.standard().build();
}
@Override
public void contextDestroyed(ServletContextEvent servletContextEvent) {
try {
System.out.println("shutting down s3Client");
if (s3Client != null) {
s3Client.shutdown();
}
com.amazonaws.http.IdleConnectionReaper.shutdown();
} catch (Throwable t) {
// log the error
}
}
}
How can I unload the classes when the application is undeployed. 取消部署应用程序时如何卸载类。
As posted in my previous comment, I found that AwsSdkMetrics bean was the culprit. 如我先前的评论中所述,我发现AwsSdkMetrics bean是元凶。 So I added this statement in my contextDestroyed method
所以我在contextDestroyed方法中添加了此语句
AwsSdkMetrics.unregisterMetricAdminMBean(); AwsSdkMetrics.unregisterMetricAdminMBean();
to unregister MetricAdminMBean. 取消注册MetricAdminMBean。
Thanks a ton to Mattias for suggesting his wonderful library which helped me figure the root cause. 感谢马蒂亚斯(Mattias)提出他的出色图书馆,这有助于我找出根本原因。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.