PDA

View Full Version : Self-scheduling Quartz jobs



rstearns01
Aug 25th, 2004, 09:28 PM
I've looked through the Spring and Quartz documentation, but can't see the solution.

I'm running in a Websphere 5.0.2 environment and I have a need for a job (call it UberJob) that runs every 8 hours looking for missing parts from orders. For any parts that it finds, I want to run concurrent jobs (ConcurrentJob) for each part that searches the vendors.

From what I've read, UberJob can get a (partially set-up) prototype ConcurrentJob from the applicationContext by exposing an applicationContext property. UberJob can then tell ConcurrentJob what part number to look for, but what would be the best way to get a handle to the scheduler so I can trigger it?
Simply get the scheduler from the factory through the appContext?
Is there a property I can create where it will be provided (i.e. setScheduler)?
Or should I wire the scheduler factory to UberJob in the context XML? I noticed in the reference doc your example doesn't have an id or name set on the factory (to discourage this misuse probably).

Thanks in advance for any help.

croudet
Aug 26th, 2004, 08:08 AM
Simply use context.getScheduler() in your Job:



public class MyJob implements Job {
/**
* @see org.quartz.Job#execute(org.quartz.JobExecutionCont ext)
*/
public void execute(JobExecutionContext context) throws JobExecutionException {
Scheduler scheduler = context.getScheduler();
...
}