Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 330358

Summary: StructuredViewer is not thread safe
Product: [RT] RAP Reporter: Daria Huber <daria.spam>
Component: RWTAssignee: Project Inbox <rap-inbox>
Status: RESOLVED INVALID QA Contact:
Severity: normal    
Priority: P3 CC: ivan, rsternberg
Version: 1.3Keywords: needinfo
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Attachments:
Description Flags
Stack trace none

Description Daria Huber CLA 2010-11-16 09:38:16 EST
Build Identifier: 3.5.2

I have a table view which is periodically refreshed by a timer task:

UICallBack.activate("refresher");
TimerTask timerTask = new TimerTask() {
            List<Object> result = null;

            public void run() {                    
                  result = refreshInputFromDb();   
                  table.getTableViewer().getControl().getDisplay().syncExec(
                        new Runnable() {
                            public void run() {
                                updateTable(result);
                            }
                        });
                    }
                }
            }

Timer timer = new Timer();
timer.schedule(timerTask, 20000, 20000);

By doubleclicking on a table entry i stop the timer task and open an editor for editing the selected object.
public void stopRefreshTimer() {
            timerTask.cancel();
            timer.cancel();
            timer = null;
            timerTask = null;
            UICallBack.deactivate("refresher");
}

When opening the editor, a ContainerCheckedTreeViewer is initialized and filled with data. 
Sometimes is an invalid thread exception throwed. 


I think StructuredViewer is not thread safe. Is it a bug or not?

Reproducible: Always
Comment 1 Daria Huber CLA 2010-11-16 09:40:08 EST
Created attachment 183225 [details]
Stack trace
Comment 2 Ralf Sternberg CLA 2010-11-16 17:45:41 EST
Why do you think that StructuredViewer should be thread safe? All SWT widget methods must be called from the UIThread. This includes updating JFace viewers, since they manipulate the widget.

You get this error because you seem to call StructuredViewer#refresh from a non-UI thread at some point.

BTW why do you call Display#syncExec() instead of asyncExec()? I'd recommend using asyncExec unless you have a very good reason not to.
Comment 3 Daria Huber CLA 2010-11-17 02:40:37 EST
Ok, it's my mistake. I call now display#asyncExec(). But i don't call StructuredViewer#refresh from a non UI-Thread. TimerTask is the only point where i access StructuredViewer in the updateTable method.
Comment 4 Ivan Furnadjiev CLA 2010-11-19 03:15:38 EST
Is the problem fixed by using display#asyncExec()?
Comment 5 Daria Huber CLA 2010-11-23 09:29:20 EST
No this problem is still not fixed. Any idea?
Comment 6 Ivan Furnadjiev CLA 2011-04-21 04:01:11 EDT
Could you provide a complete self-running snippet that demonstrate the issue?
Comment 7 Ivan Furnadjiev CLA 2011-12-12 06:00:52 EST
Any update on the complete project/snippet to reproduce the issue?
Comment 8 Daria Huber CLA 2011-12-12 06:56:43 EST
it was a bug in my code. thank's
Comment 9 Ivan Furnadjiev CLA 2011-12-12 06:59:12 EST
(In reply to comment #8)
> it was a bug in my code. thank's
Closed as INVALID in this case.