• Java定时quartz(spring)


    applicationContext-beans-task.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 id="TestTimerController" class="com.wsn.cy.boss.controller.back.command.TestTimerController" />
        
        <bean id="testdingshiJob"
            class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
            <property name="targetObject">
                <ref bean="TestTimerController"/>
            </property>
            <property name="targetMethod">
                <value>dingshi</value>
            </property>
            <!--将并发设置为false-->
             <property name="concurrent" value="false" />
        </bean>
    
        <bean id="crondingshi" class="org.springframework.scheduling.quartz.CronTriggerBean">
            <property name="jobDetail">
                <ref bean="testdingshiJob" />
            </property>
            <property name="cronExpression">
                <value>0/10 * * * * ?</value>
            </property>
        </bean>
    
        <bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
            <property name="triggers">
                <list>
                    <ref local="crondingshi" />
                </list>
            </property>
        </bean>
    
    </beans>
    View Code

    TestTimerController.java

    package com.wsn.cy.boss.controller.back.command;
    
    import java.util.Date;
    
    import org.springframework.stereotype.Controller;
    
    @Controller
    public class TestTimerController {
    
          static int count = 0;
        public static void main(String[] args) {
            // TODO Auto-generated method stub
    
        }
        
        
        public void dingshi(){
               ++count;
               System.out.println("时间=" + new Date() + " 执行了" + count + "次"); // 1次
        }
    
    }
    View Code
  • 相关阅读:
    Java:类加载器(ClassLoader)
    Java 并发:Executor
    Java 并发:线程中断-interrupt
    UNIX IPC: POSIX 消息队列 与 信号
    Java与C++区别:重载(Overloading)
    UNIX IPC: POSIX 消息队列
    PAT 1078. Hashing
    PAT 1032. Sharing
    回顾经典问题算法:LIS, LCS-(DP类别)
    url编码模块
  • 原文地址:https://www.cnblogs.com/zouteng/p/5593877.html
Copyright © 2020-2023  润新知