spring qrtz任务调度
来源:互联网 发布:苏州爱知科技厂怎么样 编辑:程序博客网 时间:2024/06/06 10:03
不继承继承基类方式::::::
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Service("bizObject")
public class ExpireJobTask {
/** Logger */
private static final Logger logger = LoggerFactory.getLogger(ExpireJobTask.class);
/**
* 业务逻辑处理
*/
public void doBiz() {
System.out.println("定时任务、、、、");
}
}
配置文件
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:util="http://www.springframework.org/schema/util"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.0.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd"
default-autowire="byName" default-lazy-init="false">
<context:component-scan base-package="com.km.framework.test" />
<!-- 线程执行器配置,用于任务注册 -->
<bean id="executor" class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">
<property name="corePoolSize" value="10" />
<property name="maxPoolSize" value="100" />
<property name="queueCapacity" value="500" />
</bean>
<!-- 调度业务 -->
<bean id="jobDetail" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<property name="targetObject" ref="bizObject" />
<property name="targetMethod" value="doBiz" />
</bean>
<bean id="cronTrigger" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
<property name="jobDetail" ref="jobDetail" />
<property name="cronExpression" value="0/5 * * * * ?" />
</bean>
<!-- <bean id="taskTrigger" class="org.springframework.scheduling.quartz.SimpleTriggerBean">
<property name="jobDetail" ref="jobDetail" />
<property name="startDelay" value="10000" />
<property name="repeatInterval" value="60000" />
</bean> -->
<!-- 设置调度 -->
<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers">
<list>
<ref bean="cronTrigger" />
</list>
</property>
<property name="taskExecutor" ref="executor" />
</bean>
</beans>
继承基类方式:::::
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.scheduling.quartz.QuartzJobBean;
import org.springframework.stereotype.Service;
public class ExpireJobTask extends QuartzJobBean {
private int timeout;
private static int i = 0;
//调度工厂实例化后,经过timeout时间开始执行调度
public void setTimeout(int timeout) {
this.timeout = timeout;
}
/**
* 要调度的具体任务
*/
@Override
protected void executeInternal(JobExecutionContext context)
throws JobExecutionException {
System.out.println("定时任务执行中…");
}
}
<bean name="job1" class="org.springframework.scheduling.quartz.JobDetailFactoryBean">
<property name="jobClass" value="com.km.framework.test.ExpireJobTask" />
<property name="jobDataAsMap">
<map>
<entry key="timeout" value="0" />
</map>
</property>
</bean>
<bean id="simpleTrigger" class="org.springframework.scheduling.quartz.SimpleTriggerFactoryBean">
<property name="jobDetail" ref="job1" />
<property name="startDelay" value="0" /><!-- 调度工厂实例化后,经过0秒开始执行调度 -->
<property name="repeatInterval" value="2000" /><!-- 每2秒调度一次 -->
</bean>
<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers">
<list>
<ref bean="simpleTrigger" />
</list>
</property>
</bean>
- spring qrtz任务调度
- spring 任务调度总结
- Spring 调度任务
- Spring调度任务
- Spring 任务调度
- Spring 调度任务
- spring quartz任务调度
- spring 任务调度总结
- Spring任务调度配置
- spring的调度任务
- spring,任务调度
- spring任务调度器
- Spring 任务调度
- spring任务调度
- Spring 调度任务
- Spring Quartz 任务调度
- Spring 3.1 任务调度
- Spring Quartz 任务调度
- LeetCode 第二十六题(Remove Duplicates from Sorted Array) java
- PHP中的自动加载
- 还在用cornerRadius设置圆角么?快来试试效率更高的新方法。
- Java中正则表达式的使用
- OKhttp源码解析---demo
- spring qrtz任务调度
- Servlet请求重定向
- android总结二: 数据库的引用
- windows 富士通打印机无效
- 剑指offer,面试题四替换空格
- java排序方法总结
- Centos在vm中设置网络环境、防火墙设置
- 【Android】ListView中getView的原理与解决多轮重复调用的方法
- android自定义无限轮播的轮播图,可动态添加指示点,可点击跳转页面