spring boot 定时任务(@EnableScheduling)

ScheduleConfig.java

@Configuration
public class ScheduleConfig implements SchedulingConfigurer {

    @Override
    public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {
        taskRegistrar.setScheduler(taskExecutor());
    }

    @Bean(destroyMethod = "shutdown")
    public Executor taskExecutor() {
        return Executors.newScheduledThreadPool(20);
    }

}

任务类

@Component
public class MyTask {

    @Scheduled(fixedRate = 5000)//每5秒执行一次
    public void getFamousVRankFromDBToCache() {
        System.out.println(new Date());
    }

}

你可能感兴趣的:(docker/k8s)