SwingWorker

Discussion in 'Java' started by Alex, Feb 8, 2004.

  1. Alex

    Alex Guest

    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();
    }
    Alex, Feb 8, 2004
    #1
    1. Advertising

  2. Alex

    Chris Smith Guest

    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
    Chris Smith, Feb 8, 2004
    #2
    1. Advertising

  3. Alex

    Alex Guest

    Thanks, I understand now.

    "Chris Smith" <> wrote in message
    news: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
    Alex, Feb 9, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Sebastian Millies

    SwingWorker and inherited thread priorities

    Sebastian Millies, Sep 12, 2005, in forum: Java
    Replies:
    5
    Views:
    2,320
    Thomas Hawtin
    Sep 12, 2005
  2. Replies:
    3
    Views:
    723
  3. Royan
    Replies:
    2
    Views:
    592
    Royan
    Apr 1, 2008
  4. Hendrik Maryns
    Replies:
    2
    Views:
    4,941
    RedGrittyBrick
    May 16, 2008
  5. Ben Phillips

    SwingWorker.execute() does nothing

    Ben Phillips, Oct 8, 2008, in forum: Java
    Replies:
    51
    Views:
    4,353
    Ben Phillips
    Oct 18, 2008
Loading...

Share This Page