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