简体   繁体   English

如何在EJB3中使用Quartz?

[英]How to use Quartz with EJB3?

I want to be able to : 我希望能够:

  • define different jobs and triggers. 定义不同的作业和触发器。
  • modify the expirations dates and intervals on demand 根据需要修改到期日期和间隔
  • pause or cancel an execution (trigger) 暂停或取消执行(触发)

the jobs would be ejbs or call ejbs and i would want to manage everything from the website (the user will have to define the executions) 工作将是ejbs或call ejbs,而我想管理网站上的所有内容(用户必须定义​​执行方式)

So i looked at the timerservice, timerobjects, timer and timerhandle. 因此,我查看了timerservice,timerobjects,timer和timerhandle。 But i think it can't answer to all my needs 但是我认为它不能满足我的所有需求

Quartz, on the other hand, allows me to do every thing that i want, but i haven't the slightest clue on how to integrate this into my jboss. 另一方面,Quartz允许我做我想做的每件事,但是我丝毫不了解如何将其集成到我的jboss中。 I read that quartz uses its own threadpool, and i don't know how to handle all this. 我读到石英使用自己的线程池,我不知道如何处理所有这些。

I use Jboss Seam in my project, but the seam/quartz integration is very limited (or the documentation is) and not 100% safe (seen on their forum : 'run forever' tasks end after only a few weeks ) 我在项目中使用了Jboss Seam,但是seam / quartz集成非常有限(或者文档很有限),而且不是100%安全的(在他们的论坛上看到: “永远运行”任务仅在几周后结束

If someone managed to integrate a good scheduler into his application server (jboss is a plus) and could give me directions, advices, or even code snippets, i would be thrilled. 如果有人设法将一个好的调度程序集成到他的应用程序服务器中(jboss是一个加号),并且可以为我提供指导,建议甚至代码段,那么我会很高兴。

Thanks in advance. 提前致谢。

I have some experience integrating Quartz into a Weblogic (no jboss experience, sorry) application server. 我有将Quartz集成到Weblogic(没有jboss经验)应用程序服务器中的经验。 Quartz has a built in listener class that will be called upon server startup (per J2EE specs) that automatically configure the Quartz scheduler. Quartz具有内置的侦听器该类将在服务器启动时(根据J2EE规范)被调用, 该类会自动配置Quartz调度程序。 Then in another startup class you can retrieve that scheduler, add jobs and begin serving those jobs. 然后,在另一个启动类中,您可以检索该调度程序,添加作业并开始为这些作业提供服务。

You generally don't need to worry about the threadpool, Quartz can handle all this itself if you want it too. 通常,您无需担心线程池,如果您愿意的话,Quartz也可以自己处理所有这些事情。 It gets its information from a properties files on startup that you can define or use the default one that comes with quartz. 它从启动时从属性文件中获取其信息,您可以定义或使用石英附带的默认文件。 I have been using the default because it works for my purposes. 我一直在使用默认值,因为它可以满足我的目的。

As far as defining jobs, you create your job classes and call your ejbs from there. 至于定义作业,您可以创建作业类并从那里调用ejb。 It is rather very simple. 这非常简单。

For your reading pleasure: 为了您的阅读乐趣:

All Quartz documentation 所有Quartz文档

Quartz JavaDoc 石英JavaDoc

Cookbook containing lots of code snippets 包含大量代码片段的食谱

Hope that's enough to get you started! 希望这足以让您入门!

Great news! 好消息! JBoss has a built-in scheduler already. JBoss已经有一个内置的调度程序。

Since the EJB 2.0 specification included running stateless session beans and MDBs at scheduled intervals, all application servers have included this capability for some time now. 由于EJB 2.0规范包括按计划的时间间隔运行无状态会话Bean和MDB,所以一段时间以来,所有应用程序服务器都已包含此功能。

Here is an example of configuring JBoss to run a class using its built-in scheduler: 这是一个使用其内置调度程序配置JBoss以运行类的示例:

http://www.jboss.org/community/wiki/Scheduler http://www.jboss.org/community/wiki/Scheduler

The best part about JBoss' implementation is that it is based on the MBean specification, which means that you can create/update/delete scheduled tasks at runtime. 关于JBoss实现的最好的部分是它基于MBean规范,这意味着您可以在运行时创建/更新/删除计划任务。

Ok, i am sorry, i found in the sources of Jboss Seam just what i needed : QuartzDispatcher to create QuartzTriggerHandle wich fires seam event at specified time and date and is manually pausable, resumable and stoppable. 好的,很抱歉,我在Jboss Seam的资源中发现了我所需要的: QuartzDispatcher创建QuartzTriggerHandle,它在指定的时间和日期触发接缝事件,并且可以手动暂停,恢复和停止。 I use an @observer on the method i wanted to execute. 我在要执行的方法上使用@observer。

It's simple, and it works so far. 这很简单,到目前为止已经可以使用。

As pointed out by Poindexter, the Quartz documentation has nice starting points: Tutorial for Developing with Quartz , Examples of Usage , Cook Book (Quick How-Tos in the form of code examples) , etc. 正如Poindexter指出的那样, Quartz文档有一个很好的起点: Quartz开发教程 ,用法示例Cook Book(以代码示例形式的快速入门)等。

The What Is Quartz article is really good too (even if a bit old now). 什么是石英”的文章也非常好(即使现在有点老了)。

For integration with JBoss, maybe have a look at How to configure a Quartz service on JBoss Wiki. 要与JBoss集成,可以看看如何在JBoss Wiki上配置Quartz服务

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM