I want to run a cron in java which will run every 'x' hrs daily. X will be decided by a value in the database which is not static. I tried something like this:
private static String cronRunTime = getCronRunTimeFromDb();
private String cronExpression = "* " + cronRunTime + " * * *";
But the main problem I am facing is I am not getting how can I configure this value in the @Scheduled annotation.
I tried something:
@Scheduled(cron = cronExpression)
public void myCron(){
}
But I am getting an error during compilation:
error: element value must be a constant expression
@Scheduled(cron = cronExpression)
Can someone please help me in solving this issue.