I need set up spring scheduled time to be executed every 15 minutes from 5 p.m till 8 a.m, how to specify such expression? And also I\'d like task be executed on we
Maven Dependency
Part of Spring Context
org.springframework
spring-context
${springframework.version}
Configuration to enable Scheduling
Reference from Documentation
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
@Configuration
@EnableScheduling
public class MyAppConfig {
//..
}
Method to fire on the Cron you specified
Reference from Documentation
// 0/15 -> Every 15 minutes on the clock
// 17-20 -> Between 5pm and 8pm on the JVM timezone
// if you want timezone specific there is a 'zone' parameter: https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/scheduling/annotation/Scheduled.html#zone--
@Scheduled(cron="0 0/15 17-20 * * ?")
public void doSomething() {
// ..
}
Documentation
Spring Documentation on Scheduling
Spring Boot
Spring Boot example of setup to run for the above cron