Home >Java >javaTutorial >Java code example of Spring Boot implementing scheduled tasks
This article mainly introduces the example code for using Spring Boot scheduled tasks. Friends who need it can refer to it
Configuring scheduled tasks in Spring Boot is extremely simple... Let’s take a look at the example code:
import org.springframework.context.annotation.Configuration; import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.scheduling.annotation.Scheduled; import java.text.SimpleDateFormat; import java.util.Date; /** * Created by winner_0715 on 2017/4/18. */ @Configuration @EnableScheduling public class SchedulingConfig { // 每5秒执行一次 @Scheduled(cron = "0/5 * * * * ?") public void scheduler() { System.out.println("SchedulingConfig.scheduler()" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())); } }
The above is the detailed content of Java code example of Spring Boot implementing scheduled tasks. For more information, please follow other related articles on the PHP Chinese website!