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.
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.
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.