Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » NatTable » GlazedListsEventLayer: multi-threading issue
GlazedListsEventLayer: multi-threading issue [message #1101454] Wed, 04 September 2013 13:27 Go to next message
Steve Kramer is currently offline Steve Kramer
Messages: 8
Registered: January 2013
Junior Member
Hi

I've come across an issue with NatTable 1.0.1 when the underlying EventList of a NatTable is updated asynchronously via a separate thread. Effectively, the NatTable doesn't seem to refresh reliably when adding multiple elements to the underlying eventList using the addAll() method. Adding a few hundred rows seems to work fine in my environment (OSX 10.7) but adding half a million rows at a time fails and the table appears empty after the update.

Looking into the details of the GlazedListsEventLayer.fireEventFromSWTDisplayThread() method I noticed that it doesn't lock the underlying eventList before firing the event to the layer stack. This allows for a race condition as the event is allowed to propagate up the layer stack before the appropriate eventList is being unlocked by the updating thread.

What is the specific reason for not locking the eventList before firing the event to the layer stack ?

The issue I described above can be reliably reproduced with a slightly modified version of the _200_Group_by example from the NatTable 1.0.1 distribution. I can email the file to anybody interested in more details. The same issue revealed another bug in the ViewportEventHandler.handleLayerEvent() method where the case handing vertical structure changes is using scrollableLayer.getColumnCount() instead of scollableLayer.getRowCount() on line 76.

Best
Steve

Re: GlazedListsEventLayer: multi-threading issue [message #1101478 is a reply to message #1101454] Wed, 04 September 2013 14:07 Go to previous messageGo to next message
Edwin Park is currently offline Edwin Park
Messages: 124
Registered: July 2009
Senior Member
I remember we had a similar situation on an application we worked on many years ago with NatTable. The problem was if you sent massive numbers of updates, you'd wind up generating massive numbers of events, which would lock up the table and do all sorts of unnecessary work. Our solution was to manually turn off updates, do the massive batch insert, and then turn on updates and refresh the table again. You may want to do something similar.

Edwin
Re: GlazedListsEventLayer: multi-threading issue [message #1101700 is a reply to message #1101478] Wed, 04 September 2013 21:01 Go to previous messageGo to next message
Steve Kramer is currently offline Steve Kramer
Messages: 8
Registered: January 2013
Junior Member
Edwin

Thanks for your suggestion but I'm wondering how such a solution would look like in details. I'm already batching the update to the underlying list into a single call to the eventList.addAll() method. In other words, I'm adding a few hundred rows to an empty table in one single statement. Sometimes it works and sometimes it doesn't depending on the thread scheduling of the machine. Another complication would be to determine the number of records that can be directly inserted into the list as opposed to be inserted via the "bulk update mechanism". Such a limit also seems to be dependent on the machine speed and OS. The simple example inserting as few as 500 records at a time is failing on a dual core laptop but works fine on an eight core desktop machine.

I guess one reliable solution would entail to force *all* updates to the eventList to be performed by the UI thread and effectively single thread the updating of the eventList. If that's the case then I don't quite see the need for the GlazedListsEventLayer. Maybe I'm missing something from an architectural point that you can shed some light on.

Thanks
Steve
Re: GlazedListsEventLayer: multi-threading issue [message #1219140 is a reply to message #1101478] Mon, 02 December 2013 10:52 Go to previous messageGo to next message
P P is currently offline P P
Messages: 3
Registered: December 2013
Junior Member
Hi Edwin,

I am using NatTable 1.0.1 for my current application and I am facing a similar issue where on adding new elements to the Eventlist the NatTable does not refresh reliably.
As per your solution we need to turn off the updates and turn them back on after the addition of new rows. Could you tell me how this can be done.
When i went thru the GlazedList(BasicEventList) code the add and addAll methods call the beginEvent and commitEvent which I believe is triggering the event listners based on the change.
Can you tell me how this can be turned off? Or if there is a different solution to this problem.
I am simply adding the new objects into the list and then calling the Structural refresh:

baseEventList.addAll(addedObjectList);
nattable.refresh();
Re: GlazedListsEventLayer: multi-threading issue [message #1219184 is a reply to message #1219140] Mon, 02 December 2013 14:19 Go to previous message
Dirk Fauth is currently offline Dirk Fauth
Messages: 1289
Registered: July 2012
Senior Member
I'm not 100% sure, but I think you need to unregister the GlazedListsEventLayer as listener from the EventList that was used to create it. Then there will be no refresh events fired automatically on list changes. Afterwards you need to register it again as listener so everything else works as intended.
Previous Topic:Info about applied Filter
Next Topic:Reference of row objects
Goto Forum:
  


Current Time: Fri Sep 19 10:05:31 GMT 2014

Powered by FUDForum. Page generated in 0.05731 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software