【发布时间】:2020-01-20 02:35:05
【问题描述】:
我想使用 spring-boot 将调度程序设计为服务。我的调度器应该是通用的,以便其他微服务可以根据需要使用它。
我尝试了普通的 spring boot 示例。
/** * 此调度程序将每 20 秒运行一次。 */ @Scheduled(fixedRate = 20 * 1000, initialDelay = 5000) 公共无效 scheduleTaskWithInitialDelay() { logger.info("Fixed Rate Task with Initail Delay 20 seconds:: Execution Time - "+dateTimeFormatter.format(LocalDateTime.now())); }
/**
* This scheduler will run on every 10 Seconds.
*/
@Scheduled(fixedRate = 10* 1000, initialDelay = 5000)
public void scheduleTaskWithInitialDelay1() {
logger.info("Fixed Rate Task With Initail Delay 10 Seconds:: Execution Time - "+dateTimeFormatter.format(LocalDateTime.now()));
}
【问题讨论】:
-
“我的调度程序应该是通用的,以便其他微服务可以根据需要使用它”是什么意思?
-
@Anil 如果你必须使用 rest api 调用,你有用于那个的 crate 控制器..意味着你必须为此创建 rest api...
标签: spring-boot scheduled-tasks quartz-scheduler