Running TimerTask

I want to run TimerTask for fixed number of times. How can i stop the timer after running it certain no of times.
[120 byte] By [Satish_Patila] at [2007-11-27 4:32:36]
# 1
for (int i = 0 ; i < numberOfTimes ; i++) { // run timer}
calvino_inda at 2007-7-12 9:42:19 > top of Java-index,Java Essentials,Java Programming...
# 2
I want to stop my scheduler after running it certain number of times.I am scheduling task as timer.schedule(new MyTask(), Calendar.getInstance().getTime(), 1000);I want my Schedular to stopped after executing 5 Times
Satish_Patila at 2007-7-12 9:42:19 > top of Java-index,Java Essentials,Java Programming...
# 3
You know how to increment a variable?
quittea at 2007-7-12 9:42:19 > top of Java-index,Java Essentials,Java Programming...
# 4

> You know how to increment a variable?

I am facing difficulty in Stopping Schedular not in arriving at some condition (Incrementing variable) . So any help in stopping schedular is appreciated.

I am using cancel()

of Timer

class. But, Some thread is running in backgroud and program is not terminating

Satish_Patila at 2007-7-12 9:42:19 > top of Java-index,Java Essentials,Java Programming...
# 5
> I am facing difficulty in Stopping Schedular not in> arriving at some condition (Incrementing> variable) .I leave it to the jury whether this matches your original question ...
quittea at 2007-7-12 9:42:19 > top of Java-index,Java Essentials,Java Programming...