вторник, 2 августа 2011 г.

Quartz: running jobs sequentially

To initialize (import dictionaries, create system users and roles, etc) our system we use quartz. But yesterday after I've created new job I saw that my new job depends on other jobs. Still I don't get how can I create dependencies over jobs and I think that the usage of dependencies in jobs is an ugly solution. The solution is simply to run jobs sequentially - one by one. But I couldn't find fast way to do that. One job runs in one thread and if I set threads count to 1, then I solve my problem. Here is the code to do that:

Properties schedProps = new Properties();
schedProps.setProperty(StdSchedulerFactory.PROP_THREAD_POOL_CLASS, SimpleThreadPool.class.getName());
schedProps.setProperty(StdSchedulerFactory.PROP_THREAD_POOL_PREFIX + ".threadCount", "1");
StdSchedulerFactory factory = new StdSchedulerFactory(schedProps);
Scheduler initScheduler = factory.getScheduler();
Now all jobs in initScheduler will run one by one.
It's simple and actually work :)

Комментариев нет:

Most popular

Authors