English 中文(简体)
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)

So i looked at the timerservice, timerobjects, timer and 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. 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)

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.

Thanks in advance.

最佳回答

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. I use an @observer on the method i wanted to execute.

It s simple, and it works so far.

问题回答

I have some experience integrating Quartz into a Weblogic (no jboss experience, sorry) application server. Quartz has a built in listener class that will be called upon server startup (per J2EE specs) that automatically configure the Quartz scheduler. 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. 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. It is rather very simple.

For your reading pleasure:

All Quartz documentation

Quartz JavaDoc

Cookbook containing lots of code snippets

Hope that s enough to get you started!

Great news! JBoss has a built-in scheduler already.

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.

Here is an example of configuring JBoss to run a class using its built-in 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.

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.

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.





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签