dcsimg
I am using java.uitl.TimerTask class. Having many tasks to execute. problem is how to stop only one TimerTask while others to continue.
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Nishat_Bhargava
Posted On:   Thursday, August 1, 2002 05:27 AM

I am using following code
public class Ping
{
Timer timer;
Timer timer1;
public Ping(int seconds)
{
timer = new Timer();
timer.schedule(new PingTask(), 1000,seconds*10000);
}
class PingTask extends TimerTask
{
public void run()
{
try
{-------code---------
}
This creates mant Threads. Now I want to stop only one thread whilie others to continue. How it will be possible

Re: I am using java.uitl.TimerTask class. Having many tasks to execute. problem is how to stop only one TimerTask while others to continue.

Posted By:   Mike_Friedrich  
Posted On:   Friday, August 2, 2002 03:13 AM

The Timer class has only one background thread, thats why the TimerTask should complete its execution quickly.


You can cancel one task with myTask.cancel(), in this case its better to keep the reference of the task object.


The task run method will always executed completly, even if cancled. So canceling a task that runs only once and is started already has no effect.


Regards, Mike

About | Sitemap | Contact