I tried using ntask(a scheduler that
uses quartz-scheduler inside) but for some reason it is not working,
I found no one to ask about that, ones that have used it don't have a
clear idea of it. Therefor they can't figure out what went wrong.
Unluckily non of my mentors are familiar with it. So I decided to
find a alternative. So I thought of java in built TimerTask
According to quartz-scheduler web site
they mention several things on “Why not just use java.util.Timer ?”
- Timers have inflexible scheduling (only able to set start-time & repeat interval, nothing based on dates, time of day, etc.)
- Timers don't utilize a thread-pool (one thread per timer)
- Timers have no real management schemes - you'd have to
write your own mechanism for being able to remember, organize and
retrieve your tasks by name, etc.
Seems like I can live with TimerTask. I don't need any “persistence mechanism” as I am starting everything all over again with server startup. And with a server restart all the threads will be gone and I just need one thread, and don't need a thread-pool. And this is so simple and I don't need to manage my tasks after I create them. And On flexibility, As I know we can give a stat date(Util.date), and that is what I am using.
Timer timer = new Timer(true); Calendar firstRun = Calendar.getInstance(); firstRun.set(Calendar.HOUR_OF_DAY,HOUR_OF_THE_DAY_TO_RUN_DB_USAGE_RETRIEVAL); firstRun.set(Calendar.MINUTE, 0); firstRun.set(Calendar.SECOND, 0); timer.schedule(checker,firstRun.getTime(), 20000);
So I created the wanted date, by getting a date and setting the time part and we are good to go.
No comments:
Post a Comment