Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Sebi Tamberg
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4181
21
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic