uniquejava / blog

My notes regarding the vibrating frontend :boom and the plain old java :rofl.
Creative Commons Zero v1.0 Universal
11 stars 5 forks source link

spring boot scheduling #307

Open uniquejava opened 4 years ago

uniquejava commented 4 years ago

Spring cron expression for every day 1:01:am

show me the java code

@EnableScheduling
@SpringBootApplication

public class AwesomeApplication {
}

@Service
@Slf4j
public class ScheduleService {
    @Autowired
    private EventMapper eventMapper;

    // second, minute, hour, day of month, month, day(s) of week
    @Scheduled(cron = "0 * * * * *")
    void checkEvents() {
       ...

    }

}

important note

zone matters in some cases

Scheduled(cron="0 1 1 * * *", zone="Europe/Istanbul")
public void doScheduledWork() {
    //complete scheduled work
}

cron format

image