如何在JBoss6中动态添加Quartz作业
我正在使用 JBoss6 并且想要动态创建 Quartz-Jobs。在作业处理期间,将定义下一次开始时间(例如,1、5 或10 小时内)。
我没有找到任何解决方案,甚至很难访问org.quartz.Scheduler
(请参阅 JBoss AS 6 中的 QuartzScheduler 注入)。
下一个问题是创建新作业,我按照教程 http:// www.quartz-scheduler.org/docs/tutorial/TutorialLesson02.html:
import static org.quartz.JobBuilder.*;
import static org.quartz.SimpleScheduleBuilder.*;
import static org.quartz.CronScheduleBuilder.*;
import static org.quartz.CalendarIntervalScheduleBuilder.*;
import static org.quartz.TriggerBuilder.*;
import static org.quartz.DateBuilder.*;
// define the job and tie it to our HelloJob class
JobDetail job = newJob(HelloJob.class)
.withIdentity("myJob", "group1") // name "myJob", group "group1"
.build();
// Trigger the job to run now, and then every 40 seconds
Trigger trigger = newTrigger()
.withIdentity("myTrigger", "group1")
.startNow()
.withSchedule(simpleSchedule()
.withIntervalInSeconds(40)
.repeatForever())
.build();
// Tell quartz to schedule the job using our trigger
sched.scheduleJob(job, trigger);
但似乎org.quartz.JobBuilder
不适用于JBoss6。如果我手动添加石英依赖项,则会在启动时出现错误(类加载问题)。该工件已定义(未显式使用 Quartz):
<dependency>
<groupId>org.jboss.jbossas</groupId>
<artifactId>jboss-as-client</artifactId>
<version>6.0.0.Final</version>
<type>pom</type>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.jboss.security</groupId>
<artifactId>jbosssx-client</artifactId>
</exclusion>
<exclusion>
<groupId>org.jboss.security</groupId>
<artifactId>jbosssx</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.jboss.spec</groupId>
<artifactId>jboss-javaee-6.0</artifactId>
<version>1.0.0.Final</version>
<type>pom</type>
<scope>provided</scope>
</dependency>
I'm using JBoss6 and want to dynamically create Quartz-Jobs. During the processing of the job the next start time will be defined (e.g. in 1, 5 or 10 hours).
I didn't find any solutions for this, it's even hard to get access to the org.quartz.Scheduler
(see QuartzScheduler injection in JBoss AS 6).
The next problem is the creation of new Jobs, I followed the tutorial http://www.quartz-scheduler.org/docs/tutorial/TutorialLesson02.html:
import static org.quartz.JobBuilder.*;
import static org.quartz.SimpleScheduleBuilder.*;
import static org.quartz.CronScheduleBuilder.*;
import static org.quartz.CalendarIntervalScheduleBuilder.*;
import static org.quartz.TriggerBuilder.*;
import static org.quartz.DateBuilder.*;
// define the job and tie it to our HelloJob class
JobDetail job = newJob(HelloJob.class)
.withIdentity("myJob", "group1") // name "myJob", group "group1"
.build();
// Trigger the job to run now, and then every 40 seconds
Trigger trigger = newTrigger()
.withIdentity("myTrigger", "group1")
.startNow()
.withSchedule(simpleSchedule()
.withIntervalInSeconds(40)
.repeatForever())
.build();
// Tell quartz to schedule the job using our trigger
sched.scheduleJob(job, trigger);
But it seems the org.quartz.JobBuilder
is not available for JBoss6. If i manually add the quartz-dependency have errors on startup (class loading issues). This artifacts are defined (without explicitly using Quartz):
<dependency>
<groupId>org.jboss.jbossas</groupId>
<artifactId>jboss-as-client</artifactId>
<version>6.0.0.Final</version>
<type>pom</type>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.jboss.security</groupId>
<artifactId>jbosssx-client</artifactId>
</exclusion>
<exclusion>
<groupId>org.jboss.security</groupId>
<artifactId>jbosssx</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.jboss.spec</groupId>
<artifactId>jboss-javaee-6.0</artifactId>
<version>1.0.0.Final</version>
<type>pom</type>
<scope>provided</scope>
</dependency>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在 JBoss 6 中,您可以使用 Quartz 库中提供的工厂类来访问 Quartz 调度程序。这应该就是您所需要的:
我们在启动时在上下文侦听器中使用它来动态调度作业。 HTH。
In JBoss 6 you can get at the Quartz scheduler using a factory class provided within the Quartz library. This should be all you need:
We use this within a context listener at start up to dynamically schedule jobs. HTH.
看来您正在学习 Quartz 2.0.x 教程。您是否尝试过 Quartz 1.x 教程?
JBoss 6 提供的版本是 Quartz 1.8.3,其中有重要的 Quartz 2.x 中的 API 更改。
It seems you are following Quartz 2.0.x tutorial. Have you tried Quartz 1.x tutorial?
The version provided with JBoss 6 is Quartz 1.8.3, and there are significant API changes in Quartz 2.x.