How to pass instance variables into Quartz job?

后端 未结 6 1487
遇见更好的自我
遇见更好的自我 2021-01-31 16:55

I wonder how to pass an instance variable externally in Quartz?

Below is pseudo code I would like to write. How can I pass externalInstance into this Job?



        
6条回答
  •  不知归路
    2021-01-31 17:33

    This is the responsibility of the JobFactory. The default PropertySettingJobFactory implementation will invoke any bean-setter methods, based on properties found in the schdeuler context, the trigger, and the job detail. So as long as you have implemnted an appropriate setContext() setter method you should be able to do any of the following:

    scheduler.getContext().put("context", context);
    

    Or

    Trigger trigger = TriggerBuilder.newTrigger()
      ...
      .usingJobData("context", context)
      .build()
    

    Or

    JobDetail job = JobBuilder.newJob(SimpleJob.class)
      ...
      .usingJobData("context", context)
      .build()
    

    Or if that isn't enough you can provide your own JobFactory class which instantiates the Job objects however you please.

提交回复
热议问题