wood burning stoves 2.0*
The moose likes Java in General and the fly likes Timer Thread is not closed Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Timer Thread is not closed" Watch "Timer Thread is not closed" New topic
Author

Timer Thread is not closed

Lalit mishra
Ranch Hand

Joined: Sep 01, 2005
Posts: 99
import java.util.Timer;
import java.util.TimerTask;
public class TimerCheck
{
Timer t = null;
TimerCheck tc;
public void main() {
tc = new TimerCheck();
tc.t = new Timer();
tc.t.schedule(new TimerCheck().new demo(), 5000);
System.out.println("In main check");
//tc.t.cancel();
}
public void hello(){

System.out.println("its working");
//tc.t.cancel();
}
public static void main(String args[]){
new TimerCheck().main();
}
class demo extends TimerTask{
public void run(){
hello();
}
}

}

Hi the above program works fine but the Timer thread is not stopped.
how can i call cancel() method to close the thread.....
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

Hi the above program works fine but the Timer thread is not stopped.

Why do you think so ?


[My Blog]
All roads lead to JavaRanch
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41165
    
  45
The first thing that pops up in my mind is: why are you creating TimerCheck objects in 3 different places? Shouldn't a single one be sufficient?


Ping & DNS - my free Android networking tools app
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Timer Thread is not closed
 
Similar Threads
Exception: Server redirected too many times (20)
Threads doubt
User Prompt Timer
TIMER CLASS
Set Timer