Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > SwingWorker

Reply
Thread Tools

SwingWorker

 
 
Alex
Guest
Posts: n/a
 
      02-08-2004
I've create a thread using SwingWorker but when I call the interrupt()
method it doesn't get interrupted.
I've checked the execution path and t.interrupt() DOES get executed in the
SwingWorker interrupt() method shown below.

public void interrupt() {
Thread t = threadVar.get();
if (t != null) {
t.interrupt();
}
threadVar.clear();
}


 
Reply With Quote
 
 
 
 
Chris Smith
Guest
Posts: n/a
 
      02-08-2004
Alex wrote:
> I've create a thread using SwingWorker but when I call the interrupt()
> method it doesn't get interrupted.
> I've checked the execution path and t.interrupt() DOES get executed in the
> SwingWorker interrupt() method shown below.


What are you expecting to happen when interrupt() is called? What will
actually happen is that the thread will be interrupted during its next
interruptible call (such as Thread.sleep or Object.wait), but will
continue to run until then. Also, it can check for interruption by
polling the Thread.interrupted() method.

If you're expecting that the thread will be immediately interrupted from
whatever it is doing (even if that's not blocking on an interruptible
call), then it's your expectation rather than the behavior that's wrong.

--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 
Reply With Quote
 
 
 
 
Alex
Guest
Posts: n/a
 
      02-09-2004
Thanks, I understand now.

"Chris Smith" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)4.net...
> Alex wrote:
> > I've create a thread using SwingWorker but when I call the interrupt()
> > method it doesn't get interrupted.
> > I've checked the execution path and t.interrupt() DOES get executed in

the
> > SwingWorker interrupt() method shown below.

>
> What are you expecting to happen when interrupt() is called? What will
> actually happen is that the thread will be interrupted during its next
> interruptible call (such as Thread.sleep or Object.wait), but will
> continue to run until then. Also, it can check for interruption by
> polling the Thread.interrupted() method.
>
> If you're expecting that the thread will be immediately interrupted from
> whatever it is doing (even if that's not blocking on an interruptible
> call), then it's your expectation rather than the behavior that's wrong.
>
> --
> www.designacourse.com
> The Easiest Way to Train Anyone... Anywhere.
>
> Chris Smith - Lead Software Developer/Technical Trainer
> MindIQ Corporation



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
SwingWorker.execute() does nothing Ben Phillips Java 51 10-18-2008 02:07 PM
SwingWorker and exceptions in the doInBackground method Hendrik Maryns Java 2 05-16-2008 10:00 AM
Loading files asynchronously using SwingWorker: method communicationproblem Royan Java 2 04-01-2008 07:34 AM
Example code from SwingWorker documentation could have race condition? lionelv@gmail.com Java 3 02-04-2007 07:27 AM
SwingWorker and inherited thread priorities Sebastian Millies Java 5 09-12-2005 04:40 PM



Advertisments