首页 技术 正文
技术 2022年11月18日
0 收藏 875 点赞 2,827 浏览 1793 个字

最近有关定时任务的需求还蛮多的,我这里呢用的是最简单的用法,后续了解更深层次的用法来优化目前的代码。

首先就是引入相关jar    quartz-1.6.4.jar  spring的jar就不说了

接下来看看配置文件 applicationContext-quartz.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”
       xsi:schemaLocation=”http://www.springframework.org/schema/beans
            http://www.springframework.org/schema/beans/spring-beans-2.0.xsd”>

<!– 实例化bean –>  
    <bean id= “flowPrizeJob” class =”com.yundao.job.FlowPrizeJob”/>  //执行任务的action
      
    <!– 配置MethodInvokingJobDetailFactoryBean –>  
    <bean id= “flowPrize”  
    class=”org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean”>  
           <property name=”targetObject” ref=”flowPrizeJob”/>  
           <property name=”targetMethod” value=”startJob”/>  
           <property name=”concurrent” value=”false”/>  
    </bean>  
      
    <!– 配置定时表达式 –>  
    <bean id= “startFlowPrize” class=”org.springframework.scheduling.quartz.CronTriggerBean” >  
           <property name=”jobDetail” ref=”flowPrize” />
          <!– 每一分钟执行一次 –>   
          <property name=”cronExpression” value=”0 0/1 * * * ?” />  
    </bean>  
      
    <!– 配置调度工厂 –>  
    <bean id= “testSchedulerFactoryBean”  
        class=”org.springframework.scheduling.quartz.SchedulerFactoryBean” lazy-init=”false”>  
           <property name=”triggers”>  
                 <list>  
                       <ref bean=”startFlowPrize” />  
                 </list>  
           </property>  
    </bean>  
</beans>

这个是我的业务实现类FlowPrizeJob

@Service(“flowPrizeJob”)
public class FlowPrizeJob {

private static final Logger     logger = LoggerFactory.getLogger(FlowPrizeJob.class);

@Autowired
    private IFlowPrizeService       iFlowPrizeService;

/**
     * 执行任务
     */
    public void startJob() {
        try {
            //具体实现
        } catch (Exception e) {
            logger.error(报错”, e);
        }
    }

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,077
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,552
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,400
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,176
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,813
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,896