views:

176

answers:

1

I have a bean that has a method executed on a schedule using <task:scheduled> in the context configuration.

Is there a way for me to find the time of the next scheduled run during execution of that method?

The same method is also executed manually, and the mechanism for receiving scheduler information may not break executions from outside the scheduler...

+1  A: 

The <task:scheduled> configuration style is a convenient shortcut on to underlying Spring factory beans that generate schedulers and schedules. As a convenience, it's useful, but is much less flexible than using the underlying scheduler factories directly.

Having said that, the schedulers themselves would need to expose the "next fire time" information via their API, and that's implementation-dependent. For example, I don't see a way to get this information from the standard ScheduledExecutorService implementations.

Quartz, however, does expose this, via the getNextFireTime() method on the Trigger class.

If you're willing to abandon <task:scheduled> and use the Quartz-Spring integration directly, then you can get access to the Trigger (or TriggerBean) and get what you want that way.

skaffman
The Spring Quartz integration is exactly where I went and it does what I need. Thank you!
Bernd Haug