• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Timer Thread is not closed

 
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.....
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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


Why do you think so ?
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic