OmniFaces ViewScoped bean的内存含义? [英] Memory implications of OmniFaces ViewScoped bean?

查看:96
本文介绍了OmniFaces ViewScoped bean的内存含义?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据我了解,ViewScoped bean仅在以下情况之一发生时被破坏:

From what I understand, ViewScoped beans only get destroyed when one of the following take place:

1)JSF使用诸如<h:commandLink...>

1) JSF sends a POST request to another page with something like a <h:commandLink...>

2)打开的bean的数量超过了最大阈值设置(默认值为15)

2) The number of open beans exceeds the maximum threshold setting (default of 15)

3)用户会话已过期

这是我的困惑:

#1是否意味着如果用户使用GET请求离开页面,即使最终在另一个页面的同一浏览器选项卡中发生了JSF POST,bean仍将保持打开状态?还是发送JSF POST后,无论用户在哪个页面上,该浏览器选项卡的所有活动@ViewScoped实例都会被销毁吗?

Does #1 mean that if a user navigates away from the page with a GET request, the bean will stay open, even if eventually a JSF POST happens in the same browser tab on another page? Or will all active @ViewScoped instances for that browser tab be destroyed once a JSF POST is sent regardless of which page the user is on?

#2是否意味着用户可以为每个@ViewScoped类具有15个活动的bean实例?还是与类无关的15个Bean实例-意味着我可以拥有5个Class1实例,5个Class2实例和5个Class3实例,而一个新的bean会破坏最旧的活动bean?

Does #2 mean that a user can have 15 bean instances active for each @ViewScoped class? Or is it 15 bean instances regardless of class -- meaning I could have 5 instances of Class1, 5 instances of Class2, and 5 instances of Class3, and a new bean would destroy the oldest active bean?

对于#3,如果将STATE_SAVING_METHOD设置为"client",那么这对销毁ViewScoped的bean有什么影响吗?我记得,如果将STATE_SAVING_METHOD设置为客户端,则需要一种方法来手动控制会话的过期时间.

For #3, if STATE_SAVING_METHOD is set to "client", will that have any implications in ViewScoped beans being destroyed? From what I remember, there needs to be a way to manually control session expiration if STATE_SAVING_METHOD is set to client.

最后,有没有一种方法可以管理活动的ViewScoped bean,以便在用户单击注销"时将其销毁?

Finally, is there a way to manage active ViewScoped beans so that they can be destroyed when a user clicks "logout" for instance?

推荐答案

我通过为每个@ViewScoped bean添加@PreDestroy方法并在销毁它时记录日志来找出答案.对于可能对此感到好奇的其他人:

I figured out the answers to these by adding a @PreDestroy method to each @ViewScoped bean, and logging when it gets destroyed. For others who might be curious about this:

对于#1,如果您使用GET请求离开页面,但是不会在以后发送后继请求,从而不会破坏Bean.该bean将一直保留在内存中,直到达到最大活动视图范围"设置,并且该豆将被销毁或会话已失效.

For #1, a bean does not get destroyed if you navigate away from the page with a GET request, but then send a post request at a later time. That bean will stay in memory until the "maximum active view scopes" setting has been reached and it's the bean's turn to be destroyed, or the session has been invalidated.

对于#2,类无关紧要.您可以有5个Class1实例,5个Class2实例和5个Class3实例,并且新的ViewScoped bean实例将销毁最旧的bean(假设您的阈值为15).

For #2, class doesn't matter. You can have 5 instances of Class1, 5 instances of Class2, and 5 instances of Class3, and a new ViewScoped bean instance will destroy the oldest bean, given your threshold is 15.

对于#3,即使将STATE_SAVING_METHOD设置为client,会话一旦失效,bean也会被破坏.

For #3, it looks like the beans are destroyed once the session has been invalidated even if STATE_SAVING_METHOD is set to client.

这篇关于OmniFaces ViewScoped bean的内存含义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆