ssm定时任务

来源:互联网 发布:keen.min.js是干嘛的 编辑:程序博客网 时间:2024/05/14 22:11
1.spring-timer.xml<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans" xmlns:task="http://www.springframework.org/schema/task"xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.3.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd http://www.springframework.org/schema/taskhttp://www.springframework.org/schema/task/spring-task-4.3.xsd"><!-- <context:component-scan base-package="com.sojson.common.timer;com.sojson.roadmanager.huifubao.timer" ><context:include-filter type="annotation" expression="org.springframework.stereotype.Component"/></context:component-scan>-->   <!-- <bean id="systemTimer" class="com.sojson.common.timer.ToTimer"/><bean id="hfbTimer" class="com.sojson.roadmanager.huifubao.timer.HfbTimer"/><bean id="notifyTimer" class="com.sojson.zhifu.timer.NotifyTimer"/><task:executor id="executor" pool-size="5" />      <task:scheduler id="scheduler" pool-size="10" />    <task:annotation-driven executor="executor" scheduler="scheduler" />    <task:scheduled-tasks>                                                          <task:scheduled ref="hfbTimer" method="successOrderSelector" cron = "*/50 * * * * ?"/>    </task:scheduled-tasks>-->    <bean id="hjTimer" class="com.sojson.roadmanager.huiju.timer.HjTimer"/>    <task:scheduled-tasks>                                                          <task:scheduled ref="hjTimer" method="updateHuijuDaiFuSuccess" cron = "0 0/10 * * * ?"/>    </task:scheduled-tasks></beans>2.java类package com.sojson.roadmanager.huiju.timer;import java.util.HashMap;import java.util.List;import java.util.Map;import javax.annotation.Resource;import org.springframework.scheduling.annotation.Scheduled;import com.sojson.common.utils.DateUtil;import com.sojson.roadmanager.huiju.service.HuiJuService;import com.sojson.zhifu.dao.SDaiFuMapper;import com.sojson.zhifu.model.SDaiFu;/** * 使用Spring订制的计划任务 * */// 此注解泛指一个spring组件而@Resource @Service是确指是哪种组件/* * @Component("hfbTimer") * @EnableScheduling */public class HjTimer {    /*     * 对应配置文件:spring-timer     * 所有定时计划任务请在这里设定     * 如果不需要,请注释     *     * 需要注意的几点:     * 1、spring的@Scheduled注解 需要写在实现上     * 2、 定时器的任务方法不能有返回值(如果有返回值,spring初始化的时候会告诉你有个错误,     * 需要设定一个proxytargetclass的某个值为true、具体就去百度google吧)     * 3、实现类上要有组件的注解@Component 剩下的就是corn表达式了、具体使用以及参数请百度google     *     * CRON表达式 含义     * "0 0 12 * * ?" 每天中午十二点触发     * "0 15 10 ? * *" 每天早上10:15触发     * "0 15 10 * * ?" 每天早上10:15触发     * "0 15 10 * * ? *" 每天早上10:15触发     * "0 15 10 * * ? 2005" 2005年的每天早上10:15触发     * "0 * 14 * * ?" 每天从下午2点开始到2点59分每分钟一次触发     * "0 0/5 14 * * ?" 每天从下午2点开始到2:55分结束每5分钟一次触发     * "0 0/5 14,18 * * ?" 每天的下午2点至2:55和6点至6点55分两个时间段内每5分钟一次触发     * "0 0-5 14 * * ?" 每天14:00至14:05每分钟一次触发 "0 10,44 14 ? 3 WED" 三月的每周三的14:10和14:44触发     * "0 15 10 ? * MON-FRI" 每个周一、周二、周三、周四、周五的10:15触发     * */    /*     * @Resource RoleService roleService;     */    /*@Scheduled(cron = "0/5 * * * * ?") // 5秒的测试不用注掉就行    @Resource    HuiJuService huiJuService;    @Resource    SDaiFuMapper sDaiFuMapper;    @Scheduled(cron = "0 0/10 * * * ?")    // 每10分钟执行一次    public void updateHuijuDaiFuSuccess() {        System.out.println("开启订单查询任务");        System.out.println(DateUtil.dateToStringWithTime());        System.out.println(Thread.currentThread().getName());        Map<String, Object> map = new HashMap<String, Object>();        map.put("status", 1);        map.put("page_sql", "LIMIT 0,1000");        map.put("roadBankName", "xx");        List<SDaiFu> sDaiFuList = sDaiFuMapper.findAll(map);// 1000条订单        System.out.println("sDaiFuList.size()===" + sDaiFuList.size());        for (SDaiFu df : sDaiFuList) {            String rb_Code = huiJuService.daifuHuiJuQuery(df.getBatchNo());            if (rb_Code.equals("100")) {// 交易成功                df.setStatus(2);                sDaiFuMapper.update(df);            }        }    }}


原创粉丝点击