开发者

Help me to understand JSF managed bean scope from concurrency view

开发者 https://www.devze.com 2023-03-27 02:08 出处:网络
Can anyone help me to understand the JSF managed bean scope from a concurrency perspective ? My Understanding:

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

My Understanding:

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.

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)

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.

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 in开发者_运维问答puts are highly appreciated.


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

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.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号