• Java Timer触发定时器


    XML:

    <!-- Java Timer定时  -->
        <!-- <bean id="shortUrlTask" class=" com.spring.common.ShortUrlTask">
        </bean>  
        <bean id="scheduleReportTask" class="org.springframework.scheduling.timer.ScheduledTimerTask">  
            <property name="timerTask" ref="shortUrlTask" />
            <property name="period">
                <value>500</value>
            </property>  
        </bean>
        
        <bean class="org.springframework.scheduling.timer.TimerFactoryBean">  
            <property name="scheduledTimerTasks">  
               <list>
                   <ref bean="scheduleReportTask"/>
               </list>  
            </property> 
        </bean> -->
        
        <!-- <bean id="SchedulerTask" class="org.springframework.scheduling.quartz.JobDetailBean">  
            <property name="jobClass">  
                <value>com.spring.common.QuatzTime</value>  
            </property>
        </bean> 
        
        <bean id="SchedulerTaskTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
          <property name="jobDetail" ref="SchedulerTask" />
          <property name="cronExpression">
           <value>0/10 * * * * ?</value>
          </property>
         </bean> -->
         
          <bean id="jobDetail" class="org.springframework.scheduling.quartz.JobDetailFactoryBean">
            <!-- durability 表示任务完成之后是否依然保留到数据库,默认false   -->
            <property name="durability" value="true" />  
            <!--     目标类  /wmuitp/src/test/SpringQuartz.java-->
            <property name="jobClass" value="com.spring.common.QuatzTime"></property>
           </bean>
           
           <!-- 另一种触发器是CornTrigger -->
         <bean id="cornTrigger" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
           <property name="jobDetail" ref="jobDetail"/>
           <!-- 每个10秒触发 -->
           <property name="cronExpression" value="0/10 27 10 * * ?"/>
        </bean> 
        
        <!-- 定义核心调度器 -->
        <bean id="scheduler" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
          <property name="triggers">
            <ref bean="cornTrigger"/>
          </property>
        </bean>

    java类中:

    public class QuatzTime extends QuartzJobBean
    {
    
        @Override
        protected void executeInternal(JobExecutionContext arg0) throws JobExecutionException
        {
            System.out.println("现在的时间是:" + nowTime());
        }
    
        public String nowTime()
        {
            SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            String time = sf.format(new Date());
            return time;
        }
    
    }
  • 相关阅读:
    pyppeteer
    maven生命周期clean,compile,install,package区别
    centos7安装anyproxy
    安装jupyter notebook
    Linux-Centos7下安装Anaconda
    python文件 启动django项目
    PyCharm实用插件
    pyqt5 安装额外的工具
    PyQt5高级界面控件之QTableWidget的具体使用方法
    k8s Metrics Server 获取资源指标与 hpa 部署
  • 原文地址:https://www.cnblogs.com/dragkiss/p/3906814.html
Copyright © 2020-2023  润新知