• Quartz定调度简单案例


    创建需要调度的业务类:

    package com.jeecms.common.quartzTask;
    
    import java.text.SimpleDateFormat;
    import java.util.Date;
    import java.util.TimerTask;
    
    public class MyTimeTask extends TimerTask {
    
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    
        @Override
        public void run() {
            System.out.println("hello:"+df.format(new Date()));
        }
    
    }

    SpringBean配置文件:

    <bean id="myTimeTask" class="com.jeecms.common.quartzTask.MyTimeTask"/>
        
        <bean id="myTimeTaskJobDetail" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
            <property name="targetObject">
                <ref bean="myTimeTask" />
            </property>
            <property name="targetMethod">
                <value>run</value>
            </property>
            <property name="concurrent">
                <value>false</value>
            </property>
        </bean>
        <bean id="myTimeTaskTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean"><!--如果项目报错,把CronTriggerBean换成CronTriggerFactoryBean -->
            <property name="jobDetail">
                <ref local="myTimeTaskJobDetail" />
            </property>
            <property name="cronExpression">
                <!-- 每隔一分钟执行一次 -->
                <!-- 0 */1 * * * ? -->
                <value>0 0/1 * * * ? </value>
            </property>
        </bean>
        
        <bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean" lazy-init="false" autowire="no">
            <property name="triggers">
                <list>
                    <ref local="myTimeTaskTrigger" />
                </list>
            </property>
            <property name="autoStartup">
                <value>true</value>
            </property>
        </bean>
  • 相关阅读:
    如何:通过对字符串应用 HTML 编码在 Web 应用程序中防止脚本侵入
    ref和out的区别?
    debug版本和release版本的区别?
    Ninject依赖注入——构造函数的注入
    WCF入门简单教程(图文) VS2010版
    WCF学习笔记(一)
    WinRt BottomAppBar
    windows 8.1 MessageDialog
    sqlServer学习2-sql脚本说明
    sqlServer学习1-sql脚本
  • 原文地址:https://www.cnblogs.com/againn/p/9437460.html
Copyright © 2020-2023  润新知