java quartz实例_一个非常简单的quartz例子

在quartz中一个作业实例必须实现org.quartz.Job接口

如:

package com.unicom.gdnum.jobs;

import java.util.*;

import org.apache.commons.logging.*;

import org.quartz.Job;

import org.quartz.JobExecutionContext;

import org.quartz.JobExecutionException;

public class HelloworldJob implements Job{

static Log log=LogFactory.getLog(HelloworldJob.class);

public  HelloworldJob() {

}

public void execute(JobExecutionContext arg0) throws JobExecutionException {

// TODO Auto-generated method stub

log.info("Hello World Quartz......."+(new Date()).toLocaleString());

}

}

quartz有自己的配置文个名为quartz.properties,如果我们不在src/(根目录)如果我们不建立文件那么quartz就会使用quartz.jar包里的这个的文件。该文件通常包含以下内容:

#

# Configure Main Scheduler Properties

#

org.quartz.scheduler.instanceName = TestScheduler

org.quartz.scheduler.instanceId = AUTO

#

# Configure ThreadPool

#

org.quartz.threadPool.class = org.quartz.simpl.SimpleThreadPool

org.quartz.threadPool.threadCount =  5

org.quartz.threadPool.threadPriority = 4

#

# Configure JobStore

#

org.quartz.jobStore.misfireThreshold = 5000

org.quartz.jobStore.class = org.quartz.simpl.RAMJobStore

# ===========================================================================

# Configure SchedulerPlugins  ===============================================

# ===========================================================================

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 = /quartz_job.xml

org.quartz.plugin.jobInitializer.overWriteExistingJobs = false

org.quartz.plugin.jobInitializer.failOnFileNotFound = true

org.quartz.plugin.shutdownhook.class = org.quartz.plugins.management.ShutdownHookPlugin

org.quartz.plugin.shutdownhook.cleanShutdown = true

以上配置quartz所需的配置,其中org.quartz.plugin.jobInitializer.fileName = /quartz_job.xml指定作业配置文件名,下面我是为HelloworldJob 写的一个配置,quartz_job.xml内容如下:

helloworld

group1

com.unicom.gdnum.jobs.HelloworldJob

test

group1

helloworld

group1

0 0/1 * * * ?

这是在tomcat中作的一个例子,当然要使用quartz面要下载其相关包!

posted on 2006-07-18 14:38 有猫相伴的日子 阅读(10260) 评论(3)  编辑  收藏 所属分类: quartz

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值