File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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 Spring in Action this week in the Spring 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: 4181
    
  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