Home >Java >javaTutorial >Java code example of Spring Boot implementing scheduled tasks

Java code example of Spring Boot implementing scheduled tasks

Y2J
Y2JOriginal
2017-05-04 09:54:341826browse

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn