简体   繁体   English

使用会话bean时的JSF内存使用问题

[英]JSF Memory Usage Issue when using using session beans

I am working on an application that has a navigation tree which is a session bean. 我正在开发一个具有导航树的应用程序,该导航树是会话bean。 Every time I invoke the page that contain this bean, my memory usage will increase. 每次我调用包含这个bean的页面时,我的内存使用量都会增加。 However, after few hours of inactivity, the memory still isn't freed. 但是,在几小时不活动后,内存仍然没有被释放。 Are there any ideas why this happens, or workarounds? 有没有想法为什么会发生这种情况或解决方法?

You can explicitly set a session timeout in the deployment descriptor, or do it programmatically (though you probably don't want to do that in a JSF application). 您可以在部署描述符中显式设置会话超时,或以编程方式执行(尽管您可能不希望在JSF应用程序中执行此操作)。

Ultimately, this is in the control of the container - the server manages when to release resources regardless of the logical expiry settings. 最终,这是对容器的控制 - 服务器管理何时释放资源,而不管逻辑到期设置如何。

You can help diagnose what is going on using listeners. 您可以使用侦听器帮助诊断正在发生的事情。 For example, you could have your bean class implement HttpSessionBindingListener . 例如,您可以让您的bean类实现HttpSessionBindingListener It will be notified when it is added or removed from a session. 在会话中添加或删除时会收到通知。 Alternatively, you could watch all session events using a HttpSessionAttributeListener (JSF can use the session to manage view state, so expect some entries you didn't define yourself). 或者,您可以使用HttpSessionAttributeListener观察所有会话事件(JSF可以使用会话来管理视图状态,因此期望您自己未定义的某些条目)。 The HttpSessionAttributeListener is defined in the web.xml: HttpSessionAttributeListener在web.xml中定义:

<listener>
    <display-name>MyListener</display-name>
    <listener-class>
        somepackage.MySessionDiagnosticListenerImpl
    </listener-class>
</listener>

If you're just leaving the server inactive, it may just be that it relies other session requests to trigger expired session cleanup and you're observing an implementation detail. 如果您只是让服务器处于非活动状态,那可能就是它依赖其他会话请求来触发过期的会话清理,并且您正在观察实现细节。 Or you may be leaking memory because you've set a reference to the object in some unmanaged class. 或者您可能正在泄漏内存,因为您在某些非托管类中设置了对象的引用。

You really need to use a profiler to know what's going on about the memory in a java app. 您真的需要使用分析器来了解Java应用程序中的内存情况。 The eclipse profiler is pretty good. 日食分析器非常好。

If its a session bean it should not be instantiated for every hit on the page inside the same session. 如果是会话bean,则不应该为同一会话内页面上的每次点击实例化它。

You also have to keep in mind that the GC will not collect the classes right away. 您还必须记住,GC不会立即收集课程。 And the GC is not necessarily dependent on the time. GC不一定取决于时间。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM