JSF 2.x @ViewScoped托管bean线程安全吗? [英] Are JSF 2.x @ViewScoped managed beans thread safe?

查看:319
本文介绍了JSF 2.x @ViewScoped托管bean线程安全吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在这个问题上google了几个小时没有eval。



WELD文档和CDI规范对于提供的范围的线程安全性很清楚。



例如:




  • 申请范围 - p>


  • 会话范围 - 不安全


  • 请求范围 -


  • 会话范围 - 安全(由于WELD代理串行访问多个请求线程)




我在JSF 2.x定义的视图范围上找不到任何东西。



与对话范围大致相同的桶,尽管多个请求绑定到单个视图/用户。我不知道是否JSF实现序列化从多个请求访问bean。



任何人都知道规范或Morraja / MyFaces实现,可以清除这一点?

解决方案

视图范围与正常使用线程安全。它只能由一个浏览器窗口/选项卡使用。即,它由在初始GET请求上设置的唯一隐藏输入字段键入。在同一视图上的每个回发将使用同一视图范围的bean。浏览器本身已在同一窗口/选项卡中同步回发请求。新的浏览器窗口/标签实际上是一个新的GET请求,因此将创建一个新的和完全独立的视图。



对于ajax回发,它们按规范排队。这在 JSF 2规范的第13.3.2节中提到: / p>


13.3.2 Ajax请求排队



所有Ajax请求必须放入客户端请求队列,然后将它们发送到
服务器,以确保Ajax请求按发送顺序处理。在队列中等待
最长的请求是下一个要发送的请求。发送请求后,Ajax请求回调函数必须从队列中删除请求
(也称为出队)。如果请求成功完成,它必须从队列中删除。如果
有一个错误,客户端必须通知,但是请求仍然必须从队列中删除,因此可以发送下一个请求
。必须发送下一个请求(队列中最早的请求)。有关Ajax请求队列的更多详细信息,请参阅 jsf.ajax.request
JavaScript文档。


仅当使用PrimeFaces时,可以使用< p:ajax async =true> 禁用排队。当结合使用视图作用域bean时,必须重新考虑与会话作用域bean相同的方式。



另请参阅:




I've been googling for a couple hours on this issue to no eval.

WELD docs and the CDI spec are pretty clear regarding thread safety of the scopes provided.

For example:

  • Application Scope - not safe

  • Session Scope - not safe

  • Request Scope - safe, always bound to a single thread

  • Conversation Scope - safe (due to the WELD proxy serializing access from multiple request threads)

I can't find anything on the View Scope defined by JSF 2.x.

It is in roughly the same bucket as the Conversation Scope in that it is very possible for multiple requests to hit the scope concurrently despite it being bound to a single view / user. What I don't know is if the JSF implementation serializes access to the bean from multiple requests.

Anyone have knowledge of the spec or of the Morraja/MyFaces implementations that could clear this up?

解决方案

The view scope is with normal usage thread safe. It can be used by only one browser window/tab. Namely, it's keyed by an unique hidden input field which is set on the initial GET request. Every postback on the same view will use the one and same view scoped bean. The browser itself already "synchronizes" postback requests in the same window/tab. A new browser window/tab is effectively a new GET request and will therefore create a new and completely independent view.

As to ajax postbacks, they are by specification queued. This is mentioned in chapter 13.3.2 of the JSF 2 specification:

13.3.2 Ajax Request Queueing

All Ajax requests must be put into a client side request queue before they are sent to the server to ensure Ajax requests are processed in the order they are sent. The request that has been waiting in the queue the longest is the next request to be sent. After a request is sent, the Ajax request callback function must remove the request from the queue (also known as dequeuing). If the request completed successfully, it must be removed from the queue. If there was an error, the client must be notified, but the request must still be removed from the queue so the next request can be sent. The next request (the oldest request in the queue) must be sent. Refer to the jsf.ajax.request JavaScript documentation for more specifics about the Ajax request queue.

Only when using PrimeFaces, queueing can be disabled with <p:ajax async="true">. When using this in combination with view scoped beans, threadsafety must be reconsidered the same way as for session scoped beans.

See also:

这篇关于JSF 2.x @ViewScoped托管bean线程安全吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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