Prev | Current Page 586 | Next

Frank Zammetti

"Practical DWR 2 Projects"

put("someData", "someRandomData");
Trigger trigger = TriggerUtils.makeHourlyTrigger();
trigger.setStartTime(new Date());
trigger.setName("MyTrigger");
sched.scheduleJob(jobDetail, trigger);
While 10 lines of code probably isn??™t much in anyone??™s book, in point of fact, two of those
lines are optional (the two dealing with the dataMap). In Quartz, everything is done in terms of
jobs and triggers. A job is the thing that will get executed on some schedule, and a trigger is
when that job will execute. Here, we begin by getting a new Scheduler instance from the factory
and starting it up. Next, we create an instance of JobDetail and populate it as appropriate,
which means giving it a name (which must be unique within the group), a group (which here
is null, which means the job is part of the default group), and telling it which class should be
executed. Next is the optional dataMap stuff, which is, as the name implies, a map of data that
will be passed to the job when it is executed. This is a good way to hand the job resources it
needs like handles to JNDI resources and such. Next, a Trigger is instantiated. There are
numerous variations on a trigger, but the one shown here is a very simple hourly trigger, so
this job will fire every hour from the time it??™s started indefinitely.


Pages:
574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598