Skip to content

Commit

Permalink
Avoid reusing default scheduler
Browse files Browse the repository at this point in the history
This closes #67

Thank you @chhil for the detailed issue report and suggested solution.

I've implemented your recommendation with a little addition to support
the ability to override default parameters using the standard jPOS
config.
  • Loading branch information
ar committed Jan 26, 2018
1 parent 0b473d1 commit 9fb8ed9
Showing 1 changed file with 29 additions and 5 deletions.
34 changes: 29 additions & 5 deletions modules/quartz/src/main/java/org/jpos/q2/QuartzAdaptor.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,18 @@
import org.quartz.impl.StdSchedulerFactory;

import java.util.Date;
import java.util.List;
import java.util.Properties;
import java.util.UUID;

@SuppressWarnings("unused unchecked")
public class QuartzAdaptor extends QBeanSupport implements XmlConfigurable {
Scheduler scheduler;
Element config;
private Scheduler scheduler;
private Element config;
protected void initService() throws Exception {
scheduler = StdSchedulerFactory.getDefaultScheduler();
scheduler = createScheduler();
QFactory factory = getFactory();
LogEvent evt = getLog().createInfo();
for (Element e : (List<Element>) config.getChildren("job")) {
for (Element e : config.getChildren("job")) {
String jobId = e.getAttributeValue("id");
if (jobId == null)
jobId = UUID.randomUUID().toString();
Expand Down Expand Up @@ -129,4 +129,28 @@ public boolean running() {
return QuartzAdaptor.this.running();
}
}

private Scheduler createScheduler() throws SchedulerException {
Properties p = new Properties();

p.setProperty("org.quartz.scheduler.instanceName", getName());
p.setProperty("org.quartz.threadPool.threadsInheritContextClassLoaderOfInitializingThread", "true");
p.setProperty("org.quartz.scheduler.rmi.proxy", "false");
p.setProperty("org.quartz.scheduler.rmi.export", "false");
p.setProperty("org.quartz.jobStore.misfireThreshold", "60000");
p.setProperty("org.quartz.threadPool.threadCount", "10");
p.setProperty("org.quartz.scheduler.instanceName", getName());
p.setProperty("org.quartz.scheduler.wrapJobExecutionInUserTransaction", "false");
p.setProperty("org.quartz.threadPool.class", "org.quartz.simpl.SimpleThreadPool");
p.setProperty("org.quartz.jobStore.class", "org.quartz.simpl.RAMJobStore");
p.setProperty("org.quartz.threadPool.threadPriority", "5");

// add ability to override defaults
cfg.keySet()
.stream()
.filter (s -> s.startsWith("org.quartz."))
.forEach(s -> p.put(s, cfg.get(s)));

return new StdSchedulerFactory(p).getScheduler();
}
}

0 comments on commit 9fb8ed9

Please sign in to comment.