spring 3.1、hibernate 4、tiles2、tomcat 7 - 清理(多次部署导致内存泄漏)
在我的网络应用程序中使用 spring、hibernate 和tiles 时,我似乎遇到了内存泄漏问题。我认为这可能是由于我的应用程序在部署之间没有自行清理造成的。我部署和取消部署很多,因为我目前刚刚学习所有这些框架。
我应该做哪些事情来清理我的网络应用程序?我目前什么也没做,因为我认为 Java 会自动进行内存清理,但是我很确定它在 Spring 时不会做所有事情,因为 tomcat 一直抱怨 permgen 内存。
我很困惑是否需要运行某些方法才能保持干净。我读到了一个 spring hook,它在某处注册应用程序,然后当它关闭时,应用程序会被正确清理吗?我不确定在新版本的 spring (3.1) 中是否有必要这样做,
例如,tomcat 不断告诉我我没有正确注销 JDBC 驱动程序(但是我认为如果检测到 tomcat 会自动执行此操作) )。
我知道这是一个非常模糊的问题,但是如果有人可以提到为了防止我的应用程序泄漏而需要做的某些事情,我可以自己用谷歌搜索它们。
谢谢!
I seem to be having a memory leak issue when using spring, hibernate, and tiles for my webapp. I think this might be caused by my application not cleaning up after itself between deployments. I deploy and undeploy a lot, since I'm currently just learning all of these frameworks.
What kind of things should I be doing to cleanup in my web application? I currently do nothing because I thought Java automatically did memory cleaning, however I'm pretty sure it doesn't do everything when it comes to spring since tomcat keeps complaining about permgen memory.
I'm confused as to whether or not I need to be running certain methods in order to keep things clean. I read about a spring hook that registers the application somewhere, then when it shuts down the application is cleaned up properly? I wasn't sure if something like that was necessary though in the new version of spring (3.1)
For example, tomcat keeps telling me that I'm not properly unregistering the JDBC driver (however I think tomcat does this automatically if it is detected).
I understand this is a hugely vague question, but if someone could mention certain things that need to be done to keep my application from leaking, I can google for them myself.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Hibernate 4.0 引入了 jboss-logging 作为依赖项,这似乎会导致 permgen 泄漏(请参阅 https://issues. jboss.org/browse/JBLOGGING-66)。
我不确定可以采取什么措施来正确修复它,但作为一种解决方法,将 jboss-logging jar 移动到 tomcats lib 目录似乎可行。
Hibernate 4.0 introduced jboss-logging as a dependency which seems to cause permgen leaks (see https://issues.jboss.org/browse/JBLOGGING-66).
I'm not sure what can be done to properly fix it but as a workaround moving the jboss-logging jar into tomcats lib directory seems to work.
无论如何,在部署新版本之前,您应该尽可能关闭生产 tomcat。
(这需要有两个 Tomcat 和一个故障转移机制,或者您只需接受服务关闭的时间长一秒,而不仅仅是更新。)
据我所知,这是确保内存泄漏的唯一方法(也考虑烫发一代)不会做任何有害的事情。
Anyway, as long as possible, you should shut down your production tomcat before you deploy a new version.
(This requrired to have two tomcats an a fail over mechanism, or you just accept that the service is down for one second longer, than just an update.)
To my knowlegs, this is the only way to make sure that a memory leak (consider the perm gen too) will not do any harmful thing.
这听起来像是我使用 Hibernate 的项目中的问题。
Hibernate 为您使用的每个域对象生成代理。这些代理保存在永久代空间下,并且在应用程序重新启动/重新部署时不会被清理。默认情况下,PermGen 空间使用的内存量相对较小,因此您可以尝试使用 -XX:MaxPermSize java 参数来增加它。这可能会缩短出现内存错误的时间,但据我所知,这个问题还没有完整的解决方案。您最终将不得不自行重新启动 tomcat。
对于 jdbc 问题,如果您手动使用连接,请确保它在 try catch finally 块中正确关闭。如果您不以这种方式使用连接对象,那么它可能会再次与 Hibernate 相关。
This sounds like issues on projects where I used Hibernate.
Hibernate generates proxies for every domain object you use. These proxies are kept under Permanent Generation space and they don't get cleaned up on application restarts/redeploys. Amount of memmory used by PermGen space is by default relatively small so you may try to increment it with the -XX:MaxPermSize java parameter. This may improve the time before you get an memmory error but there is not a complete solution I know to this problem. You will have to restart the tomcat it self eventually.
For the jdbc issue firstly if you manually use the connection make sure it's closed properly in a try catch finally block. If you don't use the connection object that way than it could be related again with Hibernate.