Reputation: 987
For the life of me, i can't seem to figure out how to configure Quartz to have two scheduler instances. I currently use quartz to get one scheduler instance but would like two instances, as described in the documentation, because i have some light weight jobs i want to run whenever i need to while limiting a few heavy weight jobs to a few instances... just as the documentation describes, but can't figure it out.
Can anyone give me a quick example of what the properties files should look like and how to instantiate the separate schedulers?
Upvotes: 3
Views: 9916
Reputation: 22333
In the non-Spring environment you should create two instances of StdSchedulerFactory
with different org.quartz.scheduler.instanceName
values. Something like this:
Properties config1 = new Properties();
Properties config2 = new Properties();
config1.setProperty("org.quartz.scheduler.instanceName", "Scheduler1");
config2.setProperty("org.quartz.scheduler.instanceName", "Scheduler2");
Scheduler scheduler1 = new StdSchedulerFactory(config1).getScheduler();
Scheduler scheduler2 = new StdSchedulerFactory(config2).getScheduler();
Upvotes: 1
Reputation: 17811
I think the key thing to getting multiple instances working is making sure to set the name of each instance to something distinct. I know for example this can cause issues when configuring multiple schedulers from spring (which I believe reflects the same underlying issue in quartz itself. See this spring forum post for details:
Upvotes: 1
Reputation: 1301
I don't have experience of configuring them via properties files, but I have mine setup in this way:
FileAppender fa = new FileAppender(new PatternLayout("%d{[dd/MM/yyy HH:mm:ss]} :: %2p :: %C{1} : %M :: %m%n"),
".\LogFiles\scheduler.log");
fa.setName("QuartzScheduler");
fa.setThreshold(Level.ALL);
fa.setAppend(true);
fa.activateOptions();
org.apache.log4j.Logger.getLogger("org.quartz").addAppender(fa);
org.apache.log4j.Logger.getLogger("org.quartz").setLevel(Level.INFO);
SimpleThreadPool threadPool = new SimpleThreadPool(25, Thread.NORM_PRIORITY);
JobStore jobStore = new RAMJobStore();
threadPool.setInstanceName("MyQuartz");
DirectSchedulerFactory.getInstance().createScheduler(threadPool, jobStore);
Scheduler operationScheduler = DirectSchedulerFactory.getInstance().getScheduler();
operationScheduler.start();
There is no reason why you couldn't create a small factory method to configure things like the amount of threads, instance name, associated log file etc. This would also have the ability of allowing your code to scale easily and create schedulers on demand, as opposed to hand editing a file.
Upvotes: 4