Pausing a Swing Worker Thread?

C

C-man

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
 
X

xarax

C-man said:
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!
 
A

Ann

xarax said:
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)
{}
}
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,539
Members
45,024
Latest member
ARDU_PROgrammER

Latest Threads

Top