File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
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: 41621
    
  55
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Timer Thread is not closed