开发者

Check if a Seam conversation is being used, without getting a lock

开发者 https://www.devze.com 2023-02-08 19:42 出处:网络
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 t

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 whe开发者_运维知识库n 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.


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 calling getConversationEntries()

Then you can call on each ConversationEntry the lockNoWait() method to get a lock. It will return immediately with false when the entry is locked by another thread. It will return true if no other thread holds a lock (in that case you would directly call unlock()).

Alternatively you might even call touch() without bothering about the locks to avoid that the conversation expires.

Best regards, Alexander.

0

精彩评论

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