jboss6 quartz2.0.2集成配置使用

 我的环境是windows 下的。所以路径都写死了。如果是linux‘环境下面的话就得重写了。特别要注意哦

先上mbean 路径jboss/server/all/deploy/schedule-service.xml

<mbean code="org.jboss.varia.scheduler.Scheduler" name="jboss.piosan.util:service=QuartzShedule">
  <attribute name="StartAtStartup">true</attribute>
  <attribute name="SchedulableClass">com.test.schedule.QuartzSchedule</attribute>
  <attribute name="SchedulableArgumentTypes">java.lang.String</attribute>
  <attribute name="SchedulableArguments">E:/java/jboss-6.1.0.Final/server/all/deploy/quartzConf/quartz.properties</attribute>
  <attribute name="InitialStartDate">NOW</attribute>
  <attribute name="SchedulePeriod">1000</attribute>
  <attribute name="InitialRepetitions">1</attribute>
 </mbean>

对应的quartz配置文件为deploy下的quartzConf/quartz.properties


#============================================================================
# Configure Main Scheduler Properties 
#============================================================================

org.quartz.scheduler.instanceName = MyScheduler
org.quartz.scheduler.instanceId = AUTO

org.quartz.scheduler.skipUpdateCheck = true

#============================================================================
# Configure ThreadPool 
#============================================================================

org.quartz.threadPool.class = org.quartz.simpl.SimpleThreadPool
org.quartz.threadPool.threadCount = 3
org.quartz.threadPool.threadPriority = 5

#============================================================================
# Configure JobStore 
#============================================================================

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

 

#============================================================================
# Configure Datasources 
#============================================================================

 

 

#============================================================================
# Configure Plugins
#============================================================================

org.quartz.plugin.triggHistory.class = org.quartz.plugins.history.LoggingJobHistoryPlugin

org.quartz.plugin.jobInitializer.class = org.quartz.plugins.xml.XMLSchedulingDataProcessorPlugin
org.quartz.plugin.jobInitializer.fileNames = E:/java/jboss-6.1.0.Final/server/all/deploy/quartzConf/quartz_data.xml
org.quartz.plugin.jobInitializer.failOnFileNotFound = true
org.quartz.plugin.jobInitializer.scanInterval = 120
org.quartz.plugin.jobInitializer.wrapInUserTransaction = false

 

接下来是quartz_data.xml即上面properties中指定的job配置文件

<?xml version="1.0" encoding="UTF-8"?>
<job-scheduling-data xmlns="http://www.quartz-scheduler.org/xml/JobSchedulingData"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.quartz-scheduler.org/xml/JobSchedulingDatahttp://www.quartz-scheduler.org/xml/job_scheduling_data_1_8.xsd"
    version="1.8">
   
    <pre-processing-commands>
        <delete-jobs-in-group>*</delete-jobs-in-group>  <!-- clear all jobs in scheduler -->
        <delete-triggers-in-group>*</delete-triggers-in-group> <!-- clear all triggers in scheduler -->
    </pre-processing-commands>
   
    <processing-directives>
        <!-- if there are any jobs/trigger in scheduler of same name (as in this file), overwrite them -->
        <overwrite-existing-data>true</overwrite-existing-data>
        <!-- if there are any jobs/trigger in scheduler of same name (as in this file), and over-write is false, ignore them rather then generating an error -->
        <ignore-duplicates>false</ignore-duplicates>
    </processing-directives>
   
    <schedule>
     <job>
         <name>MyJobTest</name>
         <job-class>com.test.schedule.TestSchedule</job-class>
   <job-data-map>
             <entry>
                 <key>name</key>
                 <value>someValue</value>
             </entry>
             <entry>
                 <key>someOtherKey</key>
                 <value>someOtherValue</value>
             </entry>
         </job-data-map>
     </job>
    
  
     <trigger>
         <cron>
    <name>MyJobTest</name>
    <job-name>MyJobTest</job-name>
    <misfire-instruction>MISFIRE_INSTRUCTION_FIRE_ONCE_NOW</misfire-instruction>
    <cron-expression>0 10/1 * * * ?</cron-expression>
   </cron>
     </trigger>
  
    </schedule>   
</job-scheduling-data>

在这个配置文件中我测试了参数的传递。就是
<job-data-map>
             <entry>
                 <key>name</key>
                 <value>someValue</value>
             </entry>
             <entry>
                 <key>someOtherKey</key>
                 <value>someOtherValue</value>
             </entry>
         </job-data-map>

如果不需要可以省略

下面上代码哦

我们是通过jboss的mbean去加载我们的job的所以先来个Schedulable

package com.test.schedule;

import java.io.File;
import java.util.Date;

import org.jboss.varia.scheduler.Schedulable;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.impl.StdSchedulerFactory;


public class QuartzSchedule implements Schedulable{
	private org.quartz.SchedulerFactory factory=null;
	private Scheduler sd=null;
	public QuartzSchedule(String fileName){
		File file=new File(fileName);
		if(file.exists()){
			System.setProperty("QUARTZ",file.getParent());
			try {
				factory=new StdSchedulerFactory(fileName);
			} catch (SchedulerException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}else{
			System.out.println(fileName+"-----------------------");
		}
		
	}
	public void perform(Date arg0, long arg1) {
		if(factory!=null){
			System.out.println("调度任务开始启动!------------");
			try {
				sd=factory.getScheduler();
				sd.start();
			} catch (SchedulerException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			System.out.println("Quartz启动完毕");
		}
	}

}


要实现schedulable接口先初始化SchedulerFactory之后就简单了。启动任务就OK

在当前测试项目中我建立了一个名为MyJobTest的任务代码如下

package com.test.schedule;

import org.quartz.Job;
import org.quartz.JobDataMap;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;

public class TestSchedule implements Job {

 public void execute(JobExecutionContext context) throws JobExecutionException {
  JobDataMap map=context.getJobDetail().getJobDataMap();
  System.out.println("我是调度任务,我正在执行!!!!!!!!!!!!!!!"+map.get("name"));
 }

}

ok全部结束注意发布地址是server/all/lib下面。另外我用的是比较新的quartz所以要替换jboss/common/lib
下面的quartz-x.x.jar为quartz-2.0.2.jar quartz-jboss-2.0.2.jar

然后重启看看吧。OK

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
资源包主要包含以下内容: ASP项目源码:每个资源包中都包含完整的ASP项目源码,这些源码采用了经典的ASP技术开发,结构清晰、注释详细,帮助用户轻松理解整个项目的逻辑和实现方式。通过这些源码,用户可以学习到ASP的基本语法、服务器端脚本编写方法、数据库操作、用户权限管理等关键技术。 数据库设计文件:为了方便用户更好地理解系统的后台逻辑,每个项目中都附带了完整的数据库设计文件。这些文件通常包括数据库结构图、数据表设计文档,以及示例数据SQL脚本。用户可以通过这些文件快速搭建项目所需的数据库环境,并了解各个数据表之间的关系和作用。 详细的开发文档:每个资源包都附有详细的开发文档,文档内容包括项目背景介绍、功能模块说明、系统流程图、用户界面设计以及关键代码解析等。这些文档为用户提供了深入的学习材料,使得即便是从零开始的开发者也能逐步掌握项目开发的全过程。 项目演示与使用指南:为帮助用户更好地理解和使用这些ASP项目,每个资源包中都包含项目的演示文件和使用指南。演示文件通常以视频或图文形式展示项目的主要功能和操作流程,使用指南则详细说明了如何配置开发环境、部署项目以及常见问题的解决方法。 毕业设计参考:对于正在准备毕业设计的学生来说,这些资源包是绝佳的参考材料。每个项目不仅功能完善、结构清晰,还符合常见的毕业设计要求和标准。通过这些项目,学生可以学习到如何从零开始构建一个完整的Web系统,并积累丰富的项目经验。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值