1. 配置自动调度的包
@Configuration
@ComponentScan(basePackages = "com.test.indexer.service")
public class AppConfig {
}

  2. 注解调度和定时任务

/**
 * 定时任务
 */
@Component
public class ScheduledTasks {
    
    private static final SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");

    @Scheduled(fixedRate = 5000)
    public void reportCurrentTime() {
        System.out.println("------------------The time now is " + dateFormat.format(new Date()));
    }
}

  3. 调用

@Configuration
@EnableAsync
@EnableScheduling
public class App {
// todo
}

  

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-16
猜你喜欢
  • 2021-10-15
  • 2022-12-23
  • 2021-07-09
  • 2022-03-09
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案