0

I am writing a JEE JAX-RS application and I have ScheduleExpressions as a cron expression (* 1 * * *) configured in the database. In my post construct I am creating timer service to run job periodically.

Now I want to expose a rest URI to list all timer scheduled jobs which are scheduled to run for today.

Currently I am using the following way to find the next schedule time. Code: EJBCronTrigger trigger = new EJBCronTrigger(scheduleExpression); Date fireTimeAfter = trigger.getFireTimeAfter(new Date());

Can any one suggest any other better or recommended way to find the next schedule time from a ScheduleExpression. Is there any kind of library exists.

nrkkalyan
  • 179
  • 2
  • 5
  • If you're calling `TimerService.createTimer`, can you use `Timer.getNextTimeout`? – Brett Kail Jan 22 '14 at 17:15
  • Yes, I can, But I want to expose this as a rest resource where one can find the schedule jobs running for a given date. Thank you for your answer. – nrkkalyan Jan 23 '14 at 23:09
  • I found another way using Spring,Check CronSequenceGenerator in spring framework. It provides a method next(Date). To construct CronSequenceGenerator object one must pass the Crontab expression. – nrkkalyan Jan 31 '14 at 21:44

1 Answers1

0
public String checkTimerStatus() {
            Timer timer = null;
            Collection<Timer> timers = service.getTimers();
            Iterator<Timer> iterator = timers.iterator();
            while (iterator.hasNext()) {
                timer = iterator.next();
                return ("Timer will expire after " +
                        timer.getTimeRemaining() + " milliseconds.");
            }
            return ("No timer found");
        }
Igor Vuković
  • 742
  • 12
  • 25