aspose file tools
The moose likes EJB and other Java EE Technologies and the fly likes EJB3 stateless session beans and Quartz Issue Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Reply Bookmark "EJB3 stateless session beans and Quartz Issue" Watch "EJB3 stateless session beans and Quartz Issue" New topic
Author

EJB3 stateless session beans and Quartz Issue

Harshi Gunarathna
Greenhorn

Joined: Oct 26, 2008
Posts: 8
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

Joined: Nov 24, 2005
Posts: 14672
    
  11


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


[My Blog]
All roads lead to JavaRanch
Harshi Gunarathna
Greenhorn

Joined: Oct 26, 2008
Posts: 8
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: EJB3 stateless session beans and Quartz Issue
 
Similar Threads
Thread Scheduler
Java out of memory Exception
Service wont registerd on application deploy
Exception in thread "DefaultQuartzScheduler_Worker-6" java.lang.NoClassDefFoundError: org/quartz/Job
org.apache.commons.configuration.ConfigurationException: Cannot locate configuration source null