Multithreaded container population

Hi all,

This post is the continuity of this one : https://vaadin.com/forum#!/thread/650690. I’m using a container to store items and Table/TreeTable to show them. User can do some operation which generates heavy computation (each operation is done in a seperated Thread) in order to populate container.

However, in this case, component (Table/TreeTable) is already attached to the UI. To avoid problems, I synchronized the access to the UI (ui.access(Runnable)) during the addition of each item. It works, but the app is blocked and inaccessible during this operation (because of VaadinSession is almost locked).

Should I detach Table/TreeTable during this kind of operation? Can I create a new container and merge it with the main one once heavy computation is done? Another solution?

Thanks in advance.
Mohammed.

The common pattern is to do the heavy computation in the background thread when not holding the lock and then wrapping only code that accesses Vaadin UI components or data model directly in UI.access(). Compute the value into temporary variables and then do a last locked block that only uses those already computed values to update the container, which should be very quick.