Mulitple threads in vaadin not rendering the UI components.

I am creating and starting multiple therads in my vaadin portlet. Each thread runs and creates a UI component( one creates a table, another creates a layout etc…). The threads run fine, backgorund process finishes and UI component is created and added to the window. BUt they are never rendered(or visible) on the GUI. When the next request goes to server,then the UI componenets show up. Even a simple resize window request or clicking on the firebug in firefox browser or just by clicking some button(which is nowhere related to the UI component that should be rendered) renders the UI component. This mighe be because, by the time the thread finish the process, the handleRenderRequest() has already been executed and finished. So when the next request goes to the server, the handleRenderRequest() is called again and then the UI components are rendered.

I have tried the ICEPush add-on too. But I still see the same issue.

I have a vertical layout, which inturn have many buttons, labels etc… that should be rendered once the background thred finishes. But it never shows up, as i said untill the next request goes to the server.

Any idea how can i force the rendering of the UI once the background thread finishes…?

The “simplest” thing to get the UI updated is by adding a “polling” component to the UI.
The progressbar component is one such and there also exsists a refresher addon.


Thanks. The refresher works fine. That is what i was looking for. But sometimes, i see “java.util.ConcurrentModificationException”. It may be because the refresher is trying to render the page while the other thread is building the UI component. I see it is coming from the paintContent() method. It occurs in 3 times in 10.
If I remove the refresher, I dont see this exception but the components are not rendered.
I tried making the thred code ‘synchronized’ too. But i still see the exception.

Any idea…?

    at org.apache.catalina.valves.ErrorReportValve.invoke(
    at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(
    at org.apache.catalina.core.StandardEngineValve.invoke(
    at org.apache.catalina.connector.CoyoteAdapter.service(
    at org.apache.coyote.http11.Http11Processor.process(
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(

Caused by: java.util.ConcurrentModificationException
at java.util.LinkedList$ListItr.checkForComodification(
at java.util.LinkedList$
at com.vaadin.ui.AbstractOrderedLayout.paintContent(
at com.vaadin.ui.AbstractComponent.paint(
at com.vaadin.terminal.gwt.server.AbstractCommunicationManager.writeUidlResponce(
at com.vaadin.terminal.gwt.server.AbstractCommunicationManager.paintAfterVariableChanges(
at com.vaadin.terminal.gwt.server.AbstractCommunicationManager.doHandleUidlRequest(
at com.vaadin.terminal.gwt.server.PortletCommunicationManager.handleUidlRequest(
at com.vaadin.terminal.gwt.server.AbstractApplicationPortlet.handleRequest(
… 129 more

You need to synchronize on the Application-instance. Maybe you want to use my addon
for this.

I have tried synchronizing on the application instance. I still see the same error. As you see in the above logs, the exception is being thrown on the list and from the attach() method. Basically, i have two threads running. Two of them add components to the list. The list being returned is a ‘unmodifiable collection’. So when the addComponent(component) is called, it is trying to add it to the list, which was set as unmodifiable by another thread. I think that is what causing the error.

In GridLayout.class-------This is what my parent layout is, where the components created by threads are added.
public Iterator getComponentIterator() {
return Collections.unmodifiableCollection(components).iterator();

Any idea…i prefer not to use any other add ons for this issue.

The iteration is over an unmodifiable wrapper but it still breaks if you modify the underlying collection while iterating. This is a general concurrency issue in Java (and other similar systems). Concurrency is not easy.

You do need to synchronize on the application instance
when you are touching Vaadin components either directly like here (iteration, adding, …) or indirectly (e.g. modifying a Vaadin data source) in a background thread.

If the iteration and the modifications take place in different threads, you need to have
the whole iteration loop in a single block synchronized to the application
. If necessary, you can make a very quick loop that just iterates over components to copy the component list to a separate temporary data structure, and then use that outside the first synchronized loop (synchronizing separately access to each component).