| 2017.10.24 | spring |
1.定时器的动态开启和关闭
SchedulerFactory sf = new StdSchedulerFactory();
Scheduler sched = sf.getScheduler();
...
sched.start();
try {
//主线程等待一分钟
Thread.sleep(60L * 1000L);
} catch (Exception e) {
}
// 关闭定时调度,定时器不再工作
sched.shutdown(true);
2.定时器顺序配置
<!-- ============= 调度业务============= -->
<bean id="articleBatchRunService" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<!-- 要调用的对象 -->
<property name="targetObject" ref="articleBatchRun" />
<!-- 要执行的方法名称 -->
<property name="targetMethod" value="count" />
<!-- 如果前一个任务还没有结束第二个任务不会启动 false -->
<property name="concurrent" value="false" />
</bean>
3.配置好spring-quartz.xml之后,在web.xml里面进行引用
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- 加载spring文件 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml,classpath:spring-quartz.xml</param-value>
</context-param>
更新列表:
参考文章: