检查 Seam 对话是否正在使用,但没有获得锁定
在我们的 Seam 应用程序中,我们有一个轮询部分,只要页面在浏览器窗口/选项卡中保持打开状态,对话就会保持活动状态,以允许用户同时使用多个对象实例,而无需进行对话当他们忙于另一页面时,它们就会在“非活动”页面上过期。
一切工作正常,但是当轮询线程发送请求而另一个请求(长时间运行)正在进行时,我们时不时会遇到可怕的并发调用对话异常。我们将并发请求超时值设置得相当高(20 秒),大多数情况下页面会在不到 2 秒的时间内返回。然而,在某些情况下,用户会处理大量数据(并且他们愿意等待这些页面加载,无论需要多长时间),因此在通用优化方面我们无能为力。
我们正在寻找的是一种方法来检查(在所有请求都经过的中央过滤器中)给定对话是否有锁,而不尝试获取一个锁(以便在有锁时不会触发异常)已经有了)。我们有办法区分我们是否正在处理这些后台线程之一(我们这样做是为了会话管理,因此它们扩展了对话,但总体上没有扩展会话)。如果我们可以确定会话已在使用中,我们可以跳过此轮询线程的处理,因为在该特定时间不需要其服务(会话正在使用中,因此没有过期的危险)。
TLDR:检查Seam对话上是否有锁,而不尝试访问它(这可能导致触发并发调用对话异常)
任何指针,建议,都非常感谢。
In our Seam app, we have a polling section that keeps the conversations active for as long as a page is kept open in a browser window/tab, to allow the user to work with multiple object instances at the same time, without having the conversations expire on the "inactive" pages while they're busy on a different one.
Everything works fine, but every now and then we get the dreaded concurrent call to conversation exception when the polling thread sends a request while another one (long running) is in progress. We've set the concurrent-request-timeout value pretty high (20s) and most of the time the pages come back in less than 2s. However, there are situations when the users deal with large volumes of data (and they're willing to wait for those pages to load, regardless of how long it takes), so there's not much we can do, in terms of generic optimization.
What we're looking for is a way to check (in a central filter that all requests go through) if there is a lock on a given conversation, without attempting to acquire one (so as to not trigger the exception if there's a lock on it already). We have means of distinguishing whether we're dealing with one of these background threads (we do that for session management, so they extend the conversations but not the session, overall). If we can identify that the conversation is already in use, we could just skip the processing of this polling thread, as its services would not be needed at that particular time (the conversation is being used, so in no danger of expiring).
TLDR: check if there's a lock on a seam conversation without trying to access it (that could lead to triggering the concurrent call to conversation exception)
Any pointers, suggestions, are greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我假设您正在使用Seam2(因为这个问题已经存在了一段时间)。
有一个会话范围的类
ConversationEntries
,它使您可以访问会话的所有对话。您可以通过调用getConversationEntries()
要求它返回有关所有对话的信息。然后您可以在每个
ConversationEntry
上调用lockNoWait()
方法来获取一把锁。当条目被另一个线程锁定时,它将立即返回false
。如果没有其他线程持有锁,它将返回true
(在这种情况下,您将直接调用unlock()
)。或者,您甚至可以调用
touch()
而无需担心锁定,以避免会话过期。此致,
亚历山大.
I assume that you are using Seam2 (as this question has been hanging around for some time).
There is a session scoped class
ConversationEntries
that gives you access to all conversations of the session. You can ask it to return information about all conversations by callinggetConversationEntries()
Then you can call on each
ConversationEntry
thelockNoWait()
method to get a lock. It will return immediately withfalse
when the entry is locked by another thread. It will returntrue
if no other thread holds a lock (in that case you would directly callunlock()
).Alternatively you might even call
touch()
without bothering about the locks to avoid that the conversation expires.Best regards,
Alexander.