This should do it for you.
@Slf4j
@Configuration
public class TestBean implements SmartInitializingSingleton {
@Inject
TaskScheduler scheduler;
@Bean
public TaskScheduler taskScheduler() {
ThreadPoolTaskScheduler te = new ThreadPoolTaskScheduler();
te.setPoolSize(4);
return te;
}
@Override
public void afterSingletonsInstantiated() {
Arrays.stream(new String[] {"PST", "MST", "CST", "EST"})
.forEach(zone -> {
scheduler.schedule(() -> {
log.info("Zone trigged: {}", zone);
}, new CronTrigger("0 0 2 * * *", TimeZone.getTimeZone(zone)));
});
}
}
You may want to separate out the different concerns of creating the scheduler bean and the task execution. Also, take care to choose a suitable scheduler that has the parallelism you need in the event that a job runs over into the trigger time of the next job.