views:

47

answers:

2

Hi, I am trying to set a scheduled task in java for running once in a day.
The problem is that it is running only in the first day.
Any idea y?
Thanks

log.info("Schdualing midnight task");
    Timer timer = new Timer();
    Calendar date = Calendar.getInstance();

    date.set(Calendar.HOUR_OF_DAY, 23);
    date.set(Calendar.MINUTE, 30);
    date.set(Calendar.SECOND, 0);

    timer.schedule(new EndOfDayRatesTimerTask(new MidnightQuotesEvent()),
            date.getTime());
+5  A: 

Use scheduleAtFixedRate() instead. For example,

TimerTask task = new EndOfDayRatesTimerTask(new MidnightQuotesEvent());
timer.scheduleAtFixedRate(task, date.getTime(), TimeUnit.DAYS.toMillis(1));
erickson
A: 

You are using the single-shot version of schedule(). There's a version that takes an extra parameter to specify the delay between subsequent executions.

Jim Garrison