1

I have defined my quartz job with the XML jobs configuration as in here example 2

http://www.mkyong.com/java/example-to-run-multiple-jobs-in-quartz/

I have other servlets wich have some init-params and my web app also has some context-params.

How do I access these parameters inside my job which implements the Job class?

Mike Laren
  • 8,028
  • 17
  • 51
  • 70

2 Answers2

0

I see several options here.

Create a holder object that would just hold the information you want to access in your job.

public class ConfigHolder {
    static public Map importantData;
}

you would then initialize the data using the servlet2 in its init method.

Schedule the job with JobDataMap like this

JobDetail jd = new JobDetail("yourjob", Scheduler.DEFAULT_GROUP, JobClass.class);
jd.getJobDataMap().put("config", configObject); 
defectus
  • 1,947
  • 2
  • 16
  • 21
0

1) One can basically access the servlet's context like this

in web.xml

<context-param>
    <param-name>quartz:scheduler-context-servlet-context-key</param-name>
    <param-value>ServletContext</param-value>
</context-param>

in code

    ServletContext MyServletContext = null;
    MyServletContext = (ServletContext) context.getScheduler().getContext().get("ServletContext");

2) And then another servlet's parameters like this

ServletContext.getServletRegistration("MyServlet").getInitParameter("MyInitParam");