现在的位置: 首页 > 综合 > 正文

spring定时任务

2014年03月11日 ⁄ 综合 ⁄ 共 1743字 ⁄ 字号 评论关闭
<?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="org.jeecgframework.core.timer" />
<task:executor id="executor" pool-size="5" />  
<task:scheduler id="scheduler" pool-size="10" />  
<task:annotation-driven executor="executor" scheduler="scheduler" />
</beans>

import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Component
public class Job {

 
    @Scheduled(cron="*/10 * * * * *") 
    public void s10(){
        System.out.println("==== 十秒执行一次=======10s");
    }
    
    @Scheduled(cron="0 */1 * * * *") 
    public void m1(){
        System.out.println("1m");
    }
    
    /**
     * 每天1点执行一次
     * */
    @Scheduled(cron="0 0 1 * * ?") 
    public void oneOClockPerDay(){
        System.out.println("1h");
    }
    
    
    
}

抱歉!评论已关闭.