开发者

Guice + Quartz + iBatis

I'm trying to wire together Guice (Java), Quartz scheduler and iBatis (iBaGuice) to do the following:

  1. Start command line utility-scanner using main()
  2. Periodically scan directory (provided as argument) for files containing formatted output (XML or YAML)
  3. When file is detected, parse and output result to the database

The problems:

  1. I used this example to wire Guice and Quartz. However I'm missing some important details which I'm asking in the comments but the post is somewhat dated so I'm quoting it here also:
  1. It's not obvious how to set-up the scheduler. Where and how would I wire the Trigger (I can use Trigger#makeMinutelyTrigger)?
  2. I really have just one type of job I will be executing, I understand that details in the JobFactory#newJob are coming from the TriggerFiredBundle parameter but where/how do I wire that? And where/how do I create or wire concrete Job?

P.S. I got a little bit furt开发者_JAVA技巧her by creating and wiring ScheduleProvider. Now I'm stuck with how to actually schedule the Job in this following snippet. It seams that my JobFactory#newJob method is never called

public class CollectorServiceImpl implements CollectorService {
Scheduler scheduler;

/**
 * @throws SchedulerException
 */
@Inject
public CollectorServiceImpl(final SchedulerFactory factory, final GuiceJobFactory jobFactory)
        throws SchedulerException {
    scheduler = factory.getScheduler();
    scheduler.setJobFactory(jobFactory);
}

/**
 * @throws SchedulerException
 * @see teradata.quantum.reporting.collector.service.CollectorService#start()
 */
@Override
public void start() throws SchedulerException {
    Trigger trigger = TriggerUtils.makeMinutelyTrigger("MIN_TRIGGER");
    scheduler.scheduleJob(trigger); // this fails trigger validation since no job name is provided
    scheduler.start();
}

}


core to your problem is, you don´t actually schedule a job class:

getScheduler().scheduleJob(new JobDetail("myFooJob", null, FooJob.class),
        TriggerUtils.makeMinutelyTrigger("MIN_TRIGGER"));

full answer & demo code on http://www.codesmell.org/blog/2009/01/quartz-fits/


Do you really need scheduling, or just execution of repeating tasks at fixed intervals? If the later, have a look at java build in ExecutorService, especially the ScheduledThreadPoolExecutor. Saves a whole framework for something quite simple :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜