Spring 框架和 Quartz 调度器
Spring framework and Quartz scheduler
我有一个 Spring MVC 网络应用程序,我想使用 Quartz 调度程序。在阅读了关于 Quartz 的文档以及它如何与 Spring 集成之后,我感到很疑惑。
Quartz 处理程序 运行 是否会作为独立于 tomcat 的单独进程,或者它只是我将添加的另一个 Maven 依赖项,能够在我的控制器中进行调度?
这是我正在阅读的教程 https://dzone.com/articles/integrating-quartz-withspring
我是在 spring REST 服务中完成的:
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.scheduling.annotation.EnableScheduling;
@SpringBootApplication
@EnableScheduling
@ComponentScan(basePackages = "com.some")
public class ApiApplication {
public static void main(final String[] args) {
SpringApplication.run(ApiApplication.class, args);
}
}
.......
@Component
public class ScheduledTasks {
@Scheduled(cron = "0 1 0 * * *")
public void expiredPromotionsTask() {
log.debug("expiredPromotionsTask begin");
try {
your code here..
log.debug("expiredPromotionsTask end");
} catch (final Exception e) {
log.error(e, "expiredPromotionsTask failed");
}
}
Quartz 只是另一个 maven 依赖项,它在后台启动一个守护线程,并在每个定义的时间间隔内持续查看 QRTZ_CRON_TRIGGERS,它存储上次作业 运行 的时间,以及它的运行时间到 运行 下一次。您可以在 http://www.javarticles.com/wp-content/uploads/2016/03/QuartzSchedulerModel.png 获得更详细的图表,这将帮助您了解它的内部工作原理。
我有一个 Spring MVC 网络应用程序,我想使用 Quartz 调度程序。在阅读了关于 Quartz 的文档以及它如何与 Spring 集成之后,我感到很疑惑。
Quartz 处理程序 运行 是否会作为独立于 tomcat 的单独进程,或者它只是我将添加的另一个 Maven 依赖项,能够在我的控制器中进行调度?
这是我正在阅读的教程 https://dzone.com/articles/integrating-quartz-withspring
我是在 spring REST 服务中完成的:
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.scheduling.annotation.EnableScheduling;
@SpringBootApplication
@EnableScheduling
@ComponentScan(basePackages = "com.some")
public class ApiApplication {
public static void main(final String[] args) {
SpringApplication.run(ApiApplication.class, args);
}
}
.......
@Component
public class ScheduledTasks {
@Scheduled(cron = "0 1 0 * * *")
public void expiredPromotionsTask() {
log.debug("expiredPromotionsTask begin");
try {
your code here..
log.debug("expiredPromotionsTask end");
} catch (final Exception e) {
log.error(e, "expiredPromotionsTask failed");
}
}
Quartz 只是另一个 maven 依赖项,它在后台启动一个守护线程,并在每个定义的时间间隔内持续查看 QRTZ_CRON_TRIGGERS,它存储上次作业 运行 的时间,以及它的运行时间到 运行 下一次。您可以在 http://www.javarticles.com/wp-content/uploads/2016/03/QuartzSchedulerModel.png 获得更详细的图表,这将帮助您了解它的内部工作原理。