How to pass instance variables into Quartz job?

后端 未结 6 1489
遇见更好的自我
遇见更好的自我 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:56

    Add the object to the JobDataMap:

    JobDetail job = JobBuilder.newJob(MyJobClass.class)
                              .withIdentity("MyIdentity",
                                            "MyGroup")
                              .build();
    job.getJobDataMap()
       .put("MyObject",
            myObject);
    

    Access the data from the JobDataMap:

    var myObject = (MyObjectClass) context.getJobDetail()
                                          .getJobDataMap()
                                          .get("carrier");
    

提交回复
热议问题