I have found an issue when one have to start SchedulerFactoryBean manually without any triggers or jobs defined in XML.
I have to load task definitions from database, so I should start SchedulerFactoryBean manually (in XML I defined property autoStartup=false). Then I discovered that setting Trigger array to the bean before staring it doesn't work as it's described:
Here's how I am trying to start the scheduler:* Register a list of Trigger objects with the Scheduler that
* this FactoryBean creates.
* <p>If the Trigger determines the corresponding JobDetail itself,
* the job will be automatically registered with the Scheduler.
* Else, the respective JobDetail needs to be registered via the
* "jobDetails" property of this FactoryBean.
Trigger[] triggerArray = createMyTriggers(....);
schedulerFactoryBean.setTriggers(triggerArray);
schedulerFactoryBean.start();
The jobs do not start. Even more: it appeared that no triggers or jobs are registered in scheduler after I start it (scheduler.getTriggerGroupNames() returns empty array, however each trigger has a group defined)!
I found out where the problem is when I took a look at source code.
It appeared that setTriggers() does not do what it is described to do - it doesn't register anything, it's just a setter. The method that does the real job is registerJobsAndTriggers(). I thought that it's being called in start() - but it's actually called in afterPropertiesSet() - which is called at bean init time![]()
The only solution I see now is to create a subclass of SchedulerFactoryBean and override start() method so that it would call registerJobsAndTriggers() before starting the Quartz scheduler.
However, I think that way SchedulerFactoryBean works by default here is wrong - the method description does not correspond to the actual implementation (setTriggers()), and it's all cool only when you start SchedulerFactoryBean automatically. I think that registerJobsAndTriggers() invocation should be moved to start() method.


Reply With Quote