Pausing a Swing Worker Thread?

Discussion in 'Java' started by C-man, Sep 17, 2004.

  1. C-man

    C-man Guest

    Does anybody out there know how to pause/resume a Swing Worker thread. I
    have implemented my program to be able to cancel the thread by checking if
    it has been interrupted() in my code. but how do I pause the thread. If I
    were to use wait() and notify() how to I implement that? Do I have to add a
    new Function to SwingWorker.java?

    Thanks alot

    Cleave
     
    C-man, Sep 17, 2004
    #1
    1. Advertising

  2. C-man

    xarax Guest

    "C-man" <> wrote in message
    news:ggJ2d.20046$yW6.5712@clgrps12...
    > Does anybody out there know how to pause/resume a Swing Worker thread. I
    > have implemented my program to be able to cancel the thread by checking if
    > it has been interrupted() in my code. but how do I pause the thread. If I
    > were to use wait() and notify() how to I implement that? Do I have to add a
    > new Function to SwingWorker.java?


    ISTR SwingWorker is an abstract class. You must extend
    it with your own methods anyway. You'll have to decide
    what it means to pause the thread, since SwingWorker
    is supposed to finish its task and then post a Runnable
    to the AWT Event Dispatch Thread (using
    SwingUtilities.invokeLater(Runnable)) to notify completion.

    --
    ----------------------------
    Jeffrey D. Smith
    Farsight Systems Corporation
    24 BURLINGTON DRIVE
    LONGMONT, CO 80501-6906
    http://www.farsight-systems.com
    z/Debug debugs your Systems/C programs running on IBM z/OS for FREE!
     
    xarax, Sep 18, 2004
    #2
    1. Advertising

  3. C-man

    Ann Guest

    "xarax" <> wrote in message
    news:rTY2d.3819$...
    > "C-man" <> wrote in message
    > news:ggJ2d.20046$yW6.5712@clgrps12...
    > > Does anybody out there know how to pause/resume a Swing Worker thread. I
    > > have implemented my program to be able to cancel the thread by checking

    if
    > > it has been interrupted() in my code. but how do I pause the thread. If

    I
    > > were to use wait() and notify() how to I implement that? Do I have to

    add a
    > > new Function to SwingWorker.java?

    >
    > ISTR SwingWorker is an abstract class. You must extend
    > it with your own methods anyway. You'll have to decide
    > what it means to pause the thread, since SwingWorker
    > is supposed to finish its task and then post a Runnable
    > to the AWT Event Dispatch Thread (using
    > SwingUtilities.invokeLater(Runnable)) to notify completion.
    >
    > --
    > ----------------------------
    > Jeffrey D. Smith
    > Farsight Systems Corporation
    > 24 BURLINGTON DRIVE
    > LONGMONT, CO 80501-6906
    > http://www.farsight-systems.com
    > z/Debug debugs your Systems/C programs running on IBM z/OS for FREE!
    >
    >

    You could use a flag in your run method. (I did not
    try to compile this.)

    loop:
    if(flag)
    {
    try
    {
    Thread.sleep(500); // half a second
    continue loop;
    }
    catch(InterruptedException e)
    {}
    }
     
    Ann, Sep 18, 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. alex
    Replies:
    1
    Views:
    659
    Lau Lei Cheong
    Feb 4, 2005
  2. Sanjay
    Replies:
    1
    Views:
    663
    George Ter-Saakov
    Feb 21, 2007
  3. sqad

    pausing a thread

    sqad, Oct 19, 2007, in forum: Java
    Replies:
    7
    Views:
    549
  4. yccheok
    Replies:
    1
    Views:
    621
    Piotr Kobzda
    Mar 28, 2008
  5. Dmitry Teslenko
    Replies:
    0
    Views:
    637
    Dmitry Teslenko
    Jan 3, 2010
Loading...

Share This Page