How to update singleton container bound to UI table?

I have a background thread which should compute some data once in a while and update singleton container with it.
There is problem with the concurrency since the background thread changes the container while there might be push for UI changes.

How should I synchronize/lock the updating process? Or am I trying to do this the wrong way?

So I’m updating static container in the thread like this:

Container c = StaticSingletonContainer.getContainer; while(true){ computedData = computeData(); c.getContainerProperty("foo", "data").setValue(computedData); Thread.sleep(5000); } tried

... synchronized (c){ c.getContainerProperty("foo", "data").setValue(computedData); } ... The singleton container is like this:

public class StaticSingletonContainer{
    public static Container container;
    public static Container getContainer(){
        if(container == null){
            container = new IndexedContainer();
            container.addContainerProperty("data", String.class,"no data" );
            container.addItem("foo");
        }
        return container;
    }
}

table is initialized like this for all UIs:

table = new Table(); table.setContainerDataSource(StaticSingletonContainer.getContainer()); and every UI has thread to push ui changes or just to repaint the table here:

while (sessionAlive) { UI.getCurrent().getSession().access(new Runnable() { @Override public void run() { } }); Thread.sleep(5000); } I get this exception:

Exception in thread "Thread-16" java.lang.IllegalStateException: A connector should not be marked as dirty while a response is being written. at com.vaadin.ui.ConnectorTracker.markDirty(ConnectorTracker.java:426) at com.vaadin.server.AbstractClientConnector.markAsDirty(AbstractClientConnector.java:138) at com.vaadin.ui.Table.markAsDirty(Table.java:1835) at com.vaadin.ui.Table.valueChange(Table.java:4187) at com.vaadin.data.util.IndexedContainer.firePropertyValueChange(IndexedContainer.java:598) at com.vaadin.data.util.IndexedContainer.access$1000(IndexedContainer.java:62) at com.vaadin.data.util.IndexedContainer$IndexedContainerProperty.setValue(IndexedContainer.java:952) at procountor.admin.BackgroundThread.run(BackgroundThread.java:78) Thx

Hi,

Containers are not thread-safe and you must not share them between different UI instances. See
ticket #5723
.

In other words, containers must be specific to a single UI and may not be bound to components in other UIs.

Just in case, that applies also to beans in a BeanItemContainer - sharing them between multiple containers causes trouble if they are mutable (you need to arrange change notification mechanism by yourself). So, if you add them to a UI-specific container in an access() method, be sure to clone them.

So the container for table should be unique for every UI and I should fetch the data via database or own data source class that implements some synchronization? Would these approaches work better?

Thanks for the answers Marko!