Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Threads and Synchronization and the fly likes Callable and SWT - How to keep Thread in Background when startet by ButtonDown-Event Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "Callable and SWT - How to keep Thread in Background when startet by ButtonDown-Event" Watch "Callable and SWT - How to keep Thread in Background when startet by ButtonDown-Event" New topic
Author

Callable and SWT - How to keep Thread in Background when startet by ButtonDown-Event

Sebi Tamberg
Greenhorn

Joined: Dec 30, 2009
Posts: 4
Hi all

I've been trying to fill a table by a background thread usint SWT and Callable. Here are the main parts of my main class:


As you can see, I start the thread within my myBtStartMouseDownEvent()-Handler-Method. However, this is no background task, the whole window freezes. Where am I going wrong?

Thanks for any suggestions.

Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4165
    
  21



You start the task in a new thread, then you use this.task.get(). The get() method waits for the task to complete before returning. So you essentially start a task in a different thread, then pause the current thread till the task is done - which behaves just like you never ran the task in the other thread to begin with. So don't call the task.get() method from the event dispatch thread.

Instead, use a call back. Have the task pass its data to the event dispatch thread as part of an event when the task is done. SwingWorker provides a nice structure to do so with in the environment of Swing. It probably works just as well in SWT apps. If not, then check to see if SWT has its own class which will help you.


Steve
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Callable and SWT - How to keep Thread in Background when startet by ButtonDown-Event
 
Similar Threads
Why can't I delete item form table.(SWT)
Understanding JTable.addColumn()
method ... not found in class ...
RCP-SWT table data on button click