帮助我从并发视图了解JSF托管bean范围 [英] Help me to understand JSF managed bean scope from concurrency view

查看:106
本文介绍了帮助我从并发视图了解JSF托管bean范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以帮助我从并发角度理解JSF托管的bean范围吗?

Can anyone help me to understand the JSF managed bean scope from a concurrency perspective ?

我的理解:

一旦我在会话范围内定义了一个bean,这意味着:只有一个用户可以访问此托管bean,因此就不可能发生并发.

Once i have a bean scoped in a session scope that's mean : there is only one user can access this managed bean so there is no possibility to concurrency occur.

此外,一旦我在请求范围内使用了bean,那么一旦请求发起,就将创建该bean. 并且一旦返回响应,该bean将被删除. (每个客户端都有此Bean的不同副本)

Also, once i use a bean in a request scope then this bean will be created once a request had initiated and that bean will be removed once a response returned. (each clients have different copy of this bean)

此外,一旦我在无作用域中使用Bean,则一旦用户调用该Bean,它将被创建,并且在调用完成后,该Bean将被删除.

Also, once i use a bean in a none scope then once the user call the bean it will be created and after finish the call the bean will be removed.

但是一旦我在应用程序范围内有了一个bean,这意味着多个客户端可以访问这个bean,所以 如果我有关键数据,则必须通过同步进行保护.

But once i have a bean in an application scope that's mean multiple client can access this bean, so if i have a critical data it must be protected by synchronization.

我们非常感谢您的所有投入.

All your inputs are highly appreciated.

推荐答案

我认为您对每个示波器寿命的理解都很好.

I think your understanding of the lifespan of each of the scopes is fine.

但是,我认为您对何时应用同步并不了解.每当您需要在一定范围内同步Bean的方法时,通常这表明Bean的范围对于它所保存的数据而言太宽了.然后,您应该将bean放在更窄的范围内,或者将数据移到更窄的范围内的另一个bean中,这样就不必进行同步了.

However, I think your understanding of when to apply synchronization is not good. Whenever you need to synchronize the methods of a bean in a certain scope, then this is usually an indication that the scope of the bean is too wide for the data it holds. You should then put the bean in a more narrow scope or to move the data into another bean in a more narrow scope, so that synchronization is not necessary.

您应将请求范围的数据(演示数据,同步表单数据等)放入请求范围.您应该将视图范围的数据(异步表单数据,rendered属性条件,隐藏"值等)放入视图范围.您应将会话范围的数据(登录的用户,用户首选项,用户特定的数据等)放入会话范围.您应将应用程序范围的数据(全局下拉列表值,配置设置等)放入应用程序范围.

You should put request scoped data (presentational data, synchronous form data, etc) in the request scope. You should put view scoped data (asynchronous form data, rendered attribute conditions, "hidden" values, etc) in the view scope. You should put session scoped data (logged-in user, user preferences, user-specific data, etc) in the session scope. You should put application scoped data (global dropdown list values, configuration settings, etc) in the application scope.

这篇关于帮助我从并发视图了解JSF托管bean范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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