• 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
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Devaka Cooray
  • Ron McLeod
  • paul wheaton
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Frits Walraven
  • Scott Selikoff

SwingWorker Threads

 
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I have a long-running task that gets launched in a SwingWorker thread from my GUI when the user presses a button. However, I'd like the user to be able to kill that long running-task with a "Stop" button.
The problems I'm running into are that
1) my long running task isn't in a loop, it's just a once-and-done long task.
2) the task that gets done is abstracted away, so all I call is "executeTask()" and that sets all the processing motion.

Unfortunately, it doesn't seem like SwingWorker.interrupt() gets me out of this situation. Basically, I just want to tell the thread to stop processing immediately, no matter what. Is there a way to do this (I've looked into using a Thread object and calling Thread.stop, but the Java 5 API has deprecated that).

Thank you!
Jeff
 
Ranch Hand
Posts: 961
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, I think it all depends on what your task does.

Is it an IO operation, a database operation or massive calculation? something that you do in a single step or it takes several steps?

If it takes several steps, then you could make your tasks interruptible. You get nothing by telling a thread to interrupt if you do not take the possible interruptions into account.



If the taks is a big operation, maybe you can perform it in smaller pieces. If your task involves networking operations then you could take java.nio into account.

And I am sure there may be many other approaches.
[ October 12, 2006: Message edited by: Edwin Dalorzo ]
 
Jeff Storey
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi. What my thread is doing is a combination of those things. It does some I/O operations, database retrievals and some massive calculations. I wanted to avoid adding interrupt handlers into EVERY step of each subtask. I really just want kill the thread in its tracks.
 
Edwin Dalorzo
Ranch Hand
Posts: 961
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


wanted to avoid adding interrupt handlers into EVERY step of each subtask.



Well, yeah. I do not know how to do that either. But if somebody knows I will be most pleased to learn it.
[ October 12, 2006: Message edited by: Edwin Dalorzo ]
 
Ew. You guys are ugly with a capital UG. Here, maybe this tiny ad can help:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic