• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic