tags:

views:

48

answers:

2

I want to write a simple timer class that fires , and makes a method call at a fixed time of every day, while the application is running.

I dont want to use Quartz as I think its a overkill for this simple problem, what are the different approaches I can try for ?

Thanks in Advance

+4  A: 

Why not use java.util.Timer and java.util.TimerTask?

duffymo
+1  A: 

The util.concurrent's ScheduledExecutorService allows you to pretty easily schedule tasks to run on a fixed delay. The signature of the schedule method is as follows:

scheduleAtFixedRate(Runnable command, long initialDelay, long period, TimeUnit unit) 

You could find the difference between the current time and the time in which you wish to have it first run. Set the difference as the value for initialDelay. Set the period to 1 and the TimeUnit unit to TimeUnit.DAYS. That will cause it to run every day at that time.

Chris Dail