Spring 定时任务设置
2018-03-30 22:39
218 查看
package com.westcredit.modules.test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.westcredit.common.persistence.MapEntity;
import com.westcredit.common.utils.IdGen;
import com.westcredit.modules.person.service.PersonService;
@Service
public class CalculationCreditPromiseIsStopTask {
@Autowired
PersonService personService;
private static transient Logger logger = LoggerFactory.getLogger(CalculationCreditPromiseIsStopTask.class);
@Autowired
public void execute() {
logger.info("信用承诺是否过期---------------------------------开始--------------------------------");
MapEntity e =new MapEntity();
e.put("name","zhangdong");
e.put("state", 1);
e.put("address", "商南金丝峡");
e.put("del_flag","1");
for(int i=0;i<10;i++){
e.put("id",IdGen.uuid());
e.put("meeting","开会"+i);
personService.save(e);
}
}
}
配置文件
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:task="http://www.springframework.org/schema/task"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-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/jee http://www.springframework.org/schema/jee/spring-jee-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/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.0.xsd
">
<!-- 配置注解扫描 -->
<context:component-scan base-package="com.westcredit"/>
<task:scheduler id="taskScheduler" pool-size="10" />
<task:scheduled-tasks scheduler="taskScheduler">
<!-- 每天23点 10分 20分 30分 40分 各执行一次
<task:scheduled ref="flmMechantAmtCountTask" method="execute" cron="0 10,20,30,40 23 * * ?"/>
-->
<task:scheduled ref="calculationCreditPromiseIsStopTask" method="execute" cron="0 0/2 * * * ?"/>
</task:scheduled-tasks>
</beans>
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.westcredit.common.persistence.MapEntity;
import com.westcredit.common.utils.IdGen;
import com.westcredit.modules.person.service.PersonService;
@Service
public class CalculationCreditPromiseIsStopTask {
@Autowired
PersonService personService;
private static transient Logger logger = LoggerFactory.getLogger(CalculationCreditPromiseIsStopTask.class);
@Autowired
public void execute() {
logger.info("信用承诺是否过期---------------------------------开始--------------------------------");
MapEntity e =new MapEntity();
e.put("name","zhangdong");
e.put("state", 1);
e.put("address", "商南金丝峡");
e.put("del_flag","1");
for(int i=0;i<10;i++){
e.put("id",IdGen.uuid());
e.put("meeting","开会"+i);
personService.save(e);
}
}
}
配置文件
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:task="http://www.springframework.org/schema/task"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-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/jee http://www.springframework.org/schema/jee/spring-jee-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/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.0.xsd
">
<!-- 配置注解扫描 -->
<context:component-scan base-package="com.westcredit"/>
<task:scheduler id="taskScheduler" pool-size="10" />
<task:scheduled-tasks scheduler="taskScheduler">
<!-- 每天23点 10分 20分 30分 40分 各执行一次
<task:scheduled ref="flmMechantAmtCountTask" method="execute" cron="0 10,20,30,40 23 * * ?"/>
-->
<task:scheduled ref="calculationCreditPromiseIsStopTask" method="execute" cron="0 0/2 * * * ?"/>
</task:scheduled-tasks>
</beans>
相关文章推荐
- spring Quartz定时任务调度 时间设置
- Quartz在Spring中动态设置cronExpression (spring设置动态定时任务)(转的)
- Quartz在Spring中动态设置cronExpression (spring设置动态定时任务)
- 【转】spring定时任务时间格式cronExpression设置(转载)
- Quartz在Spring中设置动态定时任务
- Spring 定时任务时间调度相关设置
- Quartz在Spring中动态设置cronExpression (spring设置动态定时任务)
- spring Quartz定时任务调度 时间设置
- spring 定时任务的 执行时间设置规则
- web服务器用Spring设置一个定时任务
- Quartz在Spring中动态设置cronExpression (spring设置动态定时任务)
- Spring定时任务设置
- Quartz在Spring中动态设置cronExpression (spring设置动态定时任务)
- spring 定时任务的 执行时间设置规则
- spring 定时任务的 执行时间设置规则
- Quartz动态设置任务时间/spring动态定时任务
- Quartz在Spring中动态设置cronExpression (spring设置动态定时任务)
- spring3.0设置定时任务
- Spring设置定时任务时,关于执行时间的规则设置
- spring 定时任务的 执行时间设置规则