File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes Timers Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Timers" Watch "Timers" New topic


Ahmed Basheer
Ranch Hand

Joined: Apr 15, 2004
Posts: 77
I have a need of a timer which is resettable. Once it is scheduled for say 2 minute, before 2 minute are over I should be able to reschedule it for runing for 1 more minute.
Swing timers have this capability, because they have restart method. I would avoid using swing timers in non-gui application. I can't use ELB Timer service because I am running in plain java 1.5. Some new features in Java 1.5 offer some promise but have not explored yet.

Appreciate your suggestions.
Rahul Sapkal

Joined: Jul 06, 2005
Posts: 4
You can use java.util.Timer class to achieve this.

Ahmed Basheer
Ranch Hand

Joined: Apr 15, 2004
Posts: 77
Well, java.util.TimerTask which are scheduled through java.util.Timer don't have capability to be resetted. There is no reset method on Task once it is scheduled.
Doug Trott

Joined: Jan 18, 2005
Posts: 2
Perhaps "resetting" the timer can be viewed as simply a functional requirement? I used the Java.util.Timer and canceled then recreated its task. It appears that the timer is being rescheduled, but it's really a new object.
I agree. Here's the link:
subject: Timers
It's not a secret anymore!