Quantcast
Channel: SmartClient Forums
Viewing all articles
Browse latest Browse all 4756

Question about ResultSet.find

$
0
0
I'm getting some behavior with ResultSet.find that I was not expecting.

As background, my grid is associated with a client-only data source.

Because the issue is only showing up when I am receiving asynchronous events from a server, it's a little difficult to put together sample code. Also it is timing related and therefore intermittent. So, I'm hoping just explaining the scenario will be enough.

In my main path of code, the user performs an operation that should add a new entry. My code makes an async server call to add the entry, and if that succeeds I want to add the record to my grid. Because there could be multiple clients, the server also sends out an event about the add which my client also sees and processes. Both paths call a common routine to update the grid.

The common routine uses ResultSet.find to look for a record with the given key, and if it is found it does an update otherwise it does an add.

What I am seeing from adding log messages to my code is that after the call to the server completes (the one to add the data), my client calls find to see if the record it wants to add is already there (this is because the server call is async and it would be possible that the event comes through and adds the record first). If the record is not found, then I add it. However, while the "find" has still not returned, I am getting into my event handler code which is doing another "find" for the same key. Both finds return with no matching record found, and therefore both pathways try to add the record. At this point, one of the two fails with a clientOnly error because of a duplicate key in the add.

The thing that I did not expect is that the find operation seems to be "asynchronous" in that it is giving up control of the thread and allowing asynchronous events to be handled before returning.

Question: Is this behavior expected (i.e., should I expect that events coming in on an RPC channel can be processed during the "find")? If so, do you have any recommendations how I could synchronize the threads such that the find/test/add cycle on one thread blocks this from happening on another thread at the same time? It is my understanding that none of the standard java synchronization methods are available client side.

Viewing all articles
Browse latest Browse all 4756

Trending Articles