How to update the data in table?

I met a problem about how to update the data in table by thread.



First, I create a component:


VerticalSplitPanel vsplit = new VerticalSplitPanel();
[b]
[color=#fc0404]

[/color]Second, I create a table and add the table to vsplit by addComponent();The table’s code are below:
[/b]
[code]
Table table = new Table();
table.setSizeFull();
table.setSelectable(true);
table.setImmediate(true);

	IndexedContainer c = new IndexedContainer();
	c.addContainerProperty(APPLIST_PROPERTY_ID, Integer.class, null);
	c.addContainerProperty(APPLIST_PROPERTY_APPNAME, String.class, null);
	
	//connect data source
	table.setContainerDataSource(c);

	//set column headers
	table.setColumnHeaders(column);

[/code]
[b]
[color=#fc0404]

[/color]Third, I add datas to table:(here I add one Item in table, just for test)
[/b]
Container c = table.getContainerDataSource(); Object itemId = c.addItem(); Item item = c.getItem(itemId); item.getItemProperty(APPLIST_PROPERTY_ID).setValue(a.getId()); item.getItemProperty(APPLIST_PROPERTY_APPNAME).setValue(a.getAppName());
[b]
[color=#fc0404]

[/color]Fourth, I need to update the data per 3 seconds, so , I made this class implements Runnable interface and implements the run()method.
[/b]
[code]
public void run() {
while(true){
try {
//update the data in table
table.removeAllItems();

                            //In here, suppose that I get a Object b from database, I need delete all data in table, and add the newly data in table
                            Container c = table.getContainerDataSource();
	                Object itemId = c.addItem();
	                Item item = c.getItem(itemId);
	                item.getItemProperty(APPLIST_PROPERTY_ID).setValue(b.getId());
	                item.getItemProperty(APPLIST_PROPERTY_APPNAME).setValue(b.getAppName());

			Thread.sleep(3000);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
      }

[/code]


Unfortunately,I met two problems :
One: the table’s data still hold the old data and the newly data isn’t display, why?
Two: if you click the item in table, the data will update and display the newly data, why?
How could I solve those problems? Can you help me? Thanks!

Have a look at the following
thread
.

especially this
answer
.

I saw it. But I didn’t solve this problem. My problem is the second scenario.In that problem, Archie Cobbs saw the newly add item but the item with null perporty. But in my problem, the data which table hold are still old and never display the newly data or change. When I click the item in table, the data can be update and display the newly data. why? I use the thread to get the new data and update the table.

For reference to others reading this thread: the discussion has moved to
this thread
.

When accessing Vaadin components in a background thread, you need to synchronize to the Application instance and use a push or polling solution to have the UI updated before the next user action.
This thread
has more information.