Reputation:
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?
Upvotes: 1
Views: 671
Reputation:
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");
Upvotes: 0
Reputation: 1987
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);
Upvotes: 0