-
Suggestion
-
Resolution: Fixed
NOTE: This suggestion is for Confluence Server. Using Confluence Cloud? See the corresponding suggestion.
Currently job plugin modules are not dependency-injected (or "autowired"). They are instantiated by Quartz directly instead, because the module descriptor constructs the JobDetail bean this way:
JobDetail jobDetail = new JobDetail(); jobDetail.setGroup(getPluginKey()); jobDetail.setName(getKey()); jobDetail.setJobClass(getModuleClass()); JobDataMap jobDetailMap = new JobDataMap(); jobDetailMap.put("runOncePerCluster", String.valueOf(perClusterJob)); jobDetail.setJobDataMap(jobDetailMap); return jobDetail;
Although I haven't tested it, it should be possible to construct a delegating job class and pass the autowired plugin Job to it via the JobDataMap. I think this is how the MethodInvokingJobDetailFactoryBean works in Spring.
- relates to
-
CONFCLOUD-20162 Autowire job plugin modules
- Closed
- mentioned in
-
Page Failed to load
I've implemented my patch above in Confluence 4.0.1.
After this change, job plugin module classes are required to be stateless. A single instance of the Job class is reused for all invocations of the scheduled job, so maintaining state in the object would introduce race conditions.
This is consistent with servlet, macros, event handlers, and many other plugin modules, so shouldn't be a surprise to plugin developers. However, it is inconsistent with the previous behaviour, which created a new instance of the Job class with each invocation.