java计划任务quartz使用
2007-11-21 22:39
495 查看
// 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>
----------------------------------------------------------------------------------------------------
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>
相关文章推荐
- [转][JAVA]定时任务之-Quartz使用篇
- quartz.net 使用(一)-执行定时计划任务
- Java多线程~~~ScheduledThreadPoolExecutor 计划任务类的使用
- MVC 使用Quartz.Net组件实现定时计划任务
- java类中使用quartz,设置自动任务Demo
- java类中使用quartz,设置自动任务Demo
- spring框架整合使用定时任务框架java quartz的示例代码配置
- [BAT][JAVA]定时任务之-Quartz使用篇(通过这个配置可以知道在做Quartz的时候需要的jar文件/Cron表达式使用语法/常用Cron表达式)
- Quartz在.Net网站中的使用方法(定时任务计划)
- java计划任务调度框架quartz结合spring实现调度的配置实例代码分享
- 关于Java Web 使用Spring中使用Quartz(定时调用、实现固定时间执行), 触发定时器(执行某些任务)的实例
- 【转载】使用JAVA在TOMCAT下实现计划任务监听器
- Quartz 在Java Web Application中使用 定时任务
- [译]Java定时任务调度-Quartz文档(一)初步使用
- [JAVA]定时任务之-Quartz使用篇
- [JAVA]定时任务之-Quartz使用篇
- 使用Spring来实现任务计划服务二:不继承java.util.TimerTask
- JavaSpring使用Quartz任务调度定时器
- [JAVA]定时任务之-Quartz使用篇
- JAVA 定时任务之-Quartz使用篇