java计划任务quartz使用

// java class
----------------------------------------------------------------------------------------------------
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.SchedulerFactory;
import org.quartz.impl.StdSchedulerFactory;

public class MyScheduler
 {
        public void task() throws SchedulerException
        {
            SchedulerFactory sf = new StdSchedulerFactory();
            Scheduler sched = sf.getScheduler();
            sched.start();
       }
}



//quartz.properties
------------------------------------------------------------------------------------------------------
org.quartz.scheduler.instanceName = DefaultQuartzScheduler
org.quartz.scheduler.rmi.export = false
org.quartz.scheduler.rmi.proxy = false
org.quartz.scheduler.wrapJobExecutionInUserTransaction = false

org.quartz.threadPool.class = org.quartz.simpl.SimpleThreadPool  
org.quartz.threadPool.threadCount = 10
org.quartz.threadPool.threadPriority = 5
org.quartz.threadPool.threadsInheritContextClassLoaderOfInitializingThread = true
 
org.quartz.jobStore.misfireThreshold = 60000
 
org.quartz.jobStore.class = org.quartz.simpl.RAMJobStore
 
org.quartz.plugin.triggHistory.class = org.quartz.plugins.history.LoggingTriggerHistoryPlugin
org.quartz.plugin.triggHistory.triggerFiredMessage = Trigger {1}.{0} fired job {6}.{5} at: {4, date, HH:mm:ss MM/dd/yyyy}
org.quartz.plugin.triggHistory.triggerCompleteMessage = Trigger {1}.{0} completed firing job {6}.{5} at {4, date, HH:mm:ss MM/dd/yyyy} with resulting trigger instruction code: {9}
 
org.quartz.plugin.jobInitializer.class = org.quartz.plugins.xml.JobInitializationPlugin
org.quartz.plugin.jobInitializer.fileName = scheduler.xml
org.quartz.plugin.jobInitializer.overWriteExistingJobs = true
org.quartz.plugin.jobInitializer.failOnFileNotFound = true
org.quartz.plugin.shutdownhook.class = org.quartz.plugins.management.ShutdownHookPlugin
org.quartz.plugin.shutdownhook.cleanShutdown = true



//schedule.xml
---------------------------------------------------------------------------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<quartz>
  <job>
    <job-detail>
      <name>IndexFileCreate</name>
      <group>group1</group>
      <job-class>linno.index.schedule.IndexJob</job-class>
      <job-data-map>
        <entry>
          <key>configFilePath</key>
          <value>indexer.xml</value>
        </entry>
      </job-data-map>
    </job-detail>
    <trigger>
      <cron>
        <name>IndexFileCreateTrigger</name>
        <group>group1</group>
        <job-name>IndexFileCreate</job-name>
        <job-group>group1</job-group>
       
        <!--
            Field Name      Mandatory?  Allowed Values      Allowed Special Characters 
            Seconds            YES          0-59                  , - * / 
            Minutes          YES          0-59                  , - * / 
            Hours              YES          0-23                  , - * / 
            Day of month      YES          1-31                  , - * ? / L W C 
            Month              YES          1-12 or JAN-DEC     , - * / 
            Day of week      YES          1-7 or SUN-SAT      , - * ? / L C # 
            Year            NO          empty, 1970-2099      , - * /
        -->
        <!--
            0 0 0/1 * * ?
            every one hour of every day
        -->
        <cron-expression>0 0 0/1 * * ?</cron-expression>  
     </cron>     
    </trigger>
  </job>
 
  <job>
    <job-detail>
      <name>NewIndexFileCreate</name>
      <group>group1</group>
      <job-class>linno.index.schedule.NewIndexJob</job-class>
      <job-data-map>
        <entry>
          <key>configFilePath</key>
          <value>indexer.xml</value>
        </entry>
      </job-data-map>
    </job-detail>
    <trigger>
      <cron>
        <name>NewIndexFileCreateTrigger</name>
        <group>group1</group>
        <job-name>NewIndexFileCreate</job-name>
        <job-group>group1</job-group>
        <cron-expression>0 0 2 ? * 1</cron-expression>  
     </cron>     
    </trigger>
  </job> 
</quartz>
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值