In my project requirement i wanted to have one function which will calculate next execution time using cron expression.
Here i have one cron expression which says every 25 minutes, i want to have one function which will be passed with cron expression and time and function should return next execution time.
i was wondering if any ready function available for the same.
I suppose you could easily enough write something that would tell you the approximate intervals of execution - by adding 25 minutes at a time to a given time - but I'm not sure you can query cron through Java to ask it when the next execution time is. Cron doesn't queue tasks, so you can't inquire from it when the next execution time is.
Theodore Jonathan Casser
SCJP/SCSNI/SCBCD/SCWCD/SCDJWS/SCMAD/SCEA/MCTS/MCPD... and so many more letters than you can shake a stick at!
Thanks Theodore,
Actually i had given you very simple example but i have one complex cron expression stored in database, based on that i have to calculate the next execution time and store in database so one scheduler process will check if the current time is less than the calculated time then process the transaction.
And there will be different cron expressions for different client subscriptions.
So I was looking at any generic function that can calculate next execution time from the given cron expression.
See, given that, the problem's a different one than the original example. ;)
If you're storing the times of execution in a database, it shouldn't be too hard to retrieve the time-of-last-execution from that table, calculate the next execution time (as you said) and proceed from there. You just need something to parse the expression - try using String.split() or the like to split out the fields and then you can probably very easily write a parser to get the values for each field.
Theodore Jonathan Casser
SCJP/SCSNI/SCBCD/SCWCD/SCDJWS/SCMAD/SCEA/MCTS/MCPD... and so many more letters than you can shake a stick at!
pie. tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop