hi, I am trying to use Quartz job scheduler with EJB3 stateless session beans. I created one bean by implementing the org.quartz.job and the other with the trigger which provides the schedule for the job.My requirement is to invoke a method per minute.Inside the execute method i am calling a method of another stateless session bean (which implements its' remote interface).Once the program run it throws "NullPointerException".I tried to fix it but i couldn't fix it.
@Stateless public class CronScheduleBean implements CronScheduleRemote {
public CronScheduleBean() {}
public String autoSchedule(String a)throws Exception { SchedulerFactory sf = new StdSchedulerFactory(); Scheduler sched = sf.getScheduler(); JobDetail jd = new JobDetail("job1", "group1", CronJobBean.class); CronTrigger ct = new CronTrigger("cronTrigger", "group2", "0 0/1 * * * ?");
sched.scheduleJob(jd, ct); sched.start(); return a; } -------------------------------------------------------------------- @Stateless public class CronJobBean implements CronJobRemote,Job {
Scheduler DefaultQuartzScheduler_$_NON_CLUSTERED started. ReportGenerationBean :Tue Nov 25 08:54:00 IST 2008 Job group1.job1 threw an unhandled Exception: java.lang.NullPointerException at com.mjoy.cp.reporting.CronJobBean.execute(CronJobBean.java:33) at org.quartz.core.JobRunShell.run(JobRunShell.java:202) at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:525) Job (group1.job1 threw an exception. org.quartz.SchedulerException: Job threw an unhandled exception. [See nested exception: java.lang.NullPointerException] at org.quartz.core.JobRunShell.run(JobRunShell.java:213) at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:525) Caused by: java.lang.NullPointerException
Can anyone please help me to fix this issue. Thanks in advance, Harshi.
Here, Quartz is going to instantiate a new CronJobBean, but it will not be a managed stateless bean. So nothing will be injected in reportGenerationBean. Why don't you lookup the ReportGenerationLocal manually, via the InvocationContext ? Or you can look into Quartz's EJBInvokerJob class
thanks Christophe I tried it, but still i get some new Exceptions.Can you please describe the way to apply EJBInvokerJob class with EJB or else provide me a resource to understand it properly. Because i am new to EJB as well as Quartz.