JSF 托管 Bean 性能
我有一个包含多种表单的网页。一个用于登录,另一个用于创建文章,另一个用于提交评论。现在,每个表单都由不同的支持 bean 支持,例如:loggingBean、newCommentBean 等。当生命周期执行时,即使用户仅提交“新评论”表单,它是否也会创建每个 bean 的实例?
I have a web page that has many forms. One for logging in, another for creating an article and another for submitting a comment. Now, each of these forms is backed by a different backing bean for instance: loggingBean, newCommentBean, etc. When the life cycle executes, does it create instances of each of these beans even though the user submitted only the "new comment" form?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这一切都取决于豆子的范围。每个请求都会创建一次请求 bean,但您可能不应该担心创建 bean 的开销,它很小。您通常应该更关心 Bean 停留时间过长(会话 Bean 应该是请求 Bean),这会不必要地耗尽内存。
It all depends on the scope of the beans. Request beans are created once per request but you probably shouldn't worry about the overhead of a bean creation, it's tiny. You should usually be more concerned with beans staying around too long (session beans that should be request beans) which needlessly drains memory.
这取决于您如何拥有范围 托管 bean 的定义。
编辑还有渴望您可能会觉得了解一下属性
@ManagedBean(eager = true)
是件好事。It depends on how you have the scope defined of the managed bean.
EDIT There is also the eager attribute
@ManagedBean(eager = true)
that you may find good to know.