Search code examples
javaquartz

How to get a non-serializable variable on a job using Quartz?


I am trying to get access to a non-serializable object on my job, but so far I had no luck. Here is how my code look so far

>   public class ExecuteJob extends AbstractJob {
    public static String REQUEST_NAME = "request";
    private Request request;
    @Autowired
    MyObject myObject; 
    @Override
    public void executeInternal(JobExecutionContext context) {
      JobDataMap data = context.getJobDetail().getJobDataMap();
      request = (Request) data.get(REQUEST_NAME);
      System.out.println(myObject);
      // Second way that I tried
      System.out.println(this.getObject());
     }
    }

The code that you may see above is just an example of how I am trying to get the information from "myObject". I realized that I cannot get information from an Autowired object as Quartz does not know about this annotation, so what I tried to do was create an abstract class (AbstractJob) that extends QuartzJobBean and create a method on it that may retrieve a stored object (getObject), but it always come empty. Anyone know how I would be able to get this information from "myObject" taking in consideration that it is a non-serializable object?

Thanks in advance!


Solution

  • I found this answer Custom Object parameters within Jobs using Quartz-scheduler, and creating my own job factory made it possible to have access to this object.