Spring wonderfully offers a zone
attribute to the @Scheduled
annotation. I am looking to provide the @Scheduled
method with a time zone programmatically.
For example, say I want to turn the lights on at buildings in LA and Chicago, both at midnight local time. I want to get the buildings from my repository.
Can the time zone be provided at runtime or otherwise injected?
Like:
@Scheduled(cron = "0 0 * * * *", zone = {THE_ZONE}) //midnight
public void myScheduledMethod() {
//...
building.toggleLights(); //could be LA or Chicago
}
I know that the @Scheduled
method can't take any arguments, so providing the time zone that way won't do it.