• Post Reply Bookmark Topic Watch Topic
  • New Topic

EJB3 stateless session beans and Quartz Issue  RSS feed

 
Harshi Gunarathna
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 {

@EJB
private ReportGenerationLocal reportGenerationBean;

public void execute(JobExecutionContext arg0) throws JobExecutionException {
System.out.println("ReportGenerationBean :" + new Date());

reportGenerationBean.generateEODReport("2008-10-26");

}
--------------------------------------------------------------------

Output

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.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
 
Harshi Gunarathna
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Thanks in advance,
Harshi
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!