定时任务_JAVA_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > JAVA > 定时任务

定时任务

 2017/6/29 5:31:19  PXY  程序员俱乐部  我要评论(0)
  • 摘要:packagecom.gunxq.Task;importjava.util.Date;importorg.springframework.beans.factory.annotation.Autowired;importorg.springframework.scheduling.annotation.Scheduled;importorg.springframework.stereotype.Component;importcom.gunxq.teleMarket.service
  • 标签:
package com.gunxq.Task;

import java.util.Date;

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

import com.gunxq.teleMarket.service.PhoneExtendService;

@Component("taskJob")
public class TaskJob {

@Autowired
private PhoneExtendService phoneExtendService;

@Scheduled(cron = "00 0,10,20,30,40,50 * * * ? ") // 每10分钟执行一次—— 请参考Cron表达式
public void recoveryPhone() {

System.out.println("执行任务。。。。。 " + new Date().toString());
}
}


----------------------------------------
spring-tasks.xml 配置



<?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:aop="http://www.springframework.org/schema/aop"
xmlns:c="http://www.springframework.org/schema/c" xmlns:cache="http://www.springframework.org/schema/cache"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jdbc="http://www.springframework.org/schema/jdbc" xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:lang="http://www.springframework.org/schema/lang" xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:p="http://www.springframework.org/schema/p" xmlns:task="http://www.springframework.org/schema/task"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd
http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd"
default-lazy-init="false">





<context:annotation-config /> 
    <!--  spring扫描注解的配置   --> 
    <context:component-scan base-package="com.gunxq.Task" /> 
     
<!-- 开启这个配置,spring才能识别@Scheduled注解   --> 
    <task:annotation-driven scheduler="qbScheduler" mode="proxy"/> 
    <task:scheduler id="qbScheduler" pool-size="10"/> 

</beans>



注:在线Cron在线生成器:http://cron.qqe2.com/

  • 相关文章
发表评论
用户名: 匿名