• spring scheduled


    <?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:task="http://www.springframework.org/schema/task"
        xmlns:context="http://www.springframework.org/schema/context"
        xsi:schemaLocation="http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-4.1.xsd
            http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
            http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd">
      <!--task任务扫描注解-->
        <task:annotation-driven/>

      <!--扫描包位置-->
        <context:component-scan base-package="cn.anosi.task"/>  
    </beans>

    package cn.anosi.task;

    import org.slf4j.Logger;
    import org.slf4j.LoggerFactory;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.scheduling.annotation.Scheduled;
    import org.springframework.stereotype.Component;

    import cn.anosi.service.wa.WaRefundService;

    @Component
    public class WaTask {
        @Autowired
        private WaRefundService waRefundService;
        
        protected Logger logger = LoggerFactory.getLogger(getClass().getName());

        @Scheduled(cron="0 0 0 * * ?")   //每天零点执行一次  
        public void deletePartspack()throws Exception{  
            int back=waRefundService.delete();
            logger.debug("定时删除wa_partspack表"+back+"条无效数据!");
        }
    }

    定时器任中方法务没有返回值

    "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触发

  • 相关阅读:
    unbuntu下安装flash插件
    ssh命令:使用密钥文件进行登陆
    eclipse关掉jsp,js的语法验证
    spring源码学习之:xml标签扩展配置例子
    spring源码学习之:xml配置文件标签自定义
    java多线程之:线程对象一些api
    java多线程之:Java中的ReentrantLock和synchronized两种锁定机制的对比 (转载)
    Spring Cloud(十):服务网关zuul(转)
    数据库连接池dbcp和c3po的区别
    springboot数据库连接池使用策略
  • 原文地址:https://www.cnblogs.com/god-monk/p/6519359.html
Copyright © 2020-2023  润新知