Reputation: 5747
In my web application based on vaadin I have following two classes. And in MyTable class the realTimeUpdate method is continouesly updating table values per second. Meanwhile from a user action method1 is being called for table row editing. When user action invokes method1 an "Concurrent Modification exception" occurs. What is the best solution which I can apply for this issue?
public class MyView extends CustomComponent implements View{
private IndexedContainer container = new IndexedContainer();
private Table table = new Table();
public MyView(){
......
table.setContainerDataSource(container);
}
}
public class MyTable
{
public void method1(Table table)
{
Container container = table.getContainerDataSource();
Iterator<?> iterator = container.getItemIds().iterator();
while (iterator.hasNext())
{
Object itemId = iterator.next();
...... some code to modify table row
}
}
public void realTimeUpdate(Table table)
{
Container container = table.getContainerDataSource();
Iterator<?> iterator = container.getItemIds().iterator();
while (iterator.hasNext())
{
Object itemId = iterator.next();
...... some code to update table values
}
}
}
Upvotes: 1
Views: 823
Reputation: 4967
Vaadin expects that access to it is locked properly. So when you have an external thread modifying Vaadin components or other Vaadin related classes, you must use UI.access to ensure locking. Write your realTimeUpdate method as follows:
public void realTimeUpdate(Table table) {
table.getUI().access(new Runnable() {
@Override
public void run() {
Container container = table.getContainerDataSource();
Iterator<?> iterator = container.getItemIds().iterator();
while (iterator.hasNext())
{
Object itemId = iterator.next();
...... some code to update table values
}
}
});
}
Upvotes: 2