Hi All,
I have an application deployed to
JBOSS.
I need to make a scheduler which will perform certain task with my application periodically.
For that i made a servletcontext listener and a Class implementing quartz job.
Scheduling is working fine.
But i am not able to access beans from my applicationContext so that i can user methods in those bean classes and perform the tasks.
When i tried to get AppContext in execute method in the Job class it was initializing the bean repeatedly (obviously) and the server went out of memory.
Updates :
With some changes in schedular.getContext().put(appcontext)
i am able to get the context and hit the opperations in the application.
But after a few deployements the server reans out of memory.
That is the real trouble for me as it forces me the restart the server again.
i have used below code in the initialize segment of my servletcontextinitiliaer
public void contextInitialized(ServletContextEvent arg0)
{
ApplicationContext appCtx = new ClassPathXmlApplicationContext("WEB-INF/classes/applicationContext.xml");
System.out.println("THE APPLICATION STARTED");
try{
// Initiate a Schedule Factory
SchedulerFactory schedulerFactory = new StdSchedulerFactory();
// Retrieve a scheduler from schedule factory
Scheduler scheduler = schedulerFactory.getScheduler();
long ctime = System.currentTimeMillis();
JobDetail jobDetail =
new JobDetail("jobDetail-s1", "jobDetailGroup-s1", SimpleQuartzJob.class);
jobDetail.getJobDataMap().put("appContext", appCtx);
SimpleTrigger simpleTrigger =
new SimpleTrigger("simpleTrigger", "triggerGroup-s1");
simpleTrigger.setStartTime(new Date());
simpleTrigger.setRepeatInterval(300*1000);
simpleTrigger.setRepeatCount(100);
scheduler.getContext().put("appContext", appCtx);//setting appContext
scheduler.scheduleJob(jobDetail, simpleTrigger);
}
Also seems that i am not able to access the DB.
With following exception at the deployement:
org.quartz.JobPersistenceException: Failed to obtain DB connection from data source 'springNonTxDataSource.quartzScheduler': java.lang.NullPointerException [See nested exception: java.lang.NullPointerException]
at org.quartz.impl.jdbcjobstore.JobStoreCMT.getNonManagedTXConnection(JobStoreCMT.java:170)
at org.quartz.impl.jdbcjobstore.JobStoreSupport.doRecoverMisfires(JobStoreSupport.java:3107)
at org.quartz.impl.jdbcjobstore.JobStoreSupport$MisfireHandler.manage(JobStoreSupport.java:3896)
at org.quartz.impl.jdbcjobstore.JobStoreSupport$MisfireHandler.run(JobStoreSupport.java:3916)
Caused by: java.lang.NullPointerException
at org.quartz.impl.jdbcjobstore.JobStoreCMT.getNonManagedTXConnection(JobStoreCMT.java:162)
... 3 more
17:31:35,024 INFO [STDOUT] 3376051 [QuartzScheduler_quartzScheduler-NON_CLUSTERED_MisfireHandler] ERROR org.springframework.scheduling.quartz.LocalDataSourceJobStore - MisfireHandler: Error handling misfires: Failed to obtain DB connection from data source 'springNonTxDataSource.quartzScheduler': java.lang.NullPointerException
org.quartz.JobPersistenceException: Failed to obtain DB connection from data source 'springNonTxDataSource.quartzScheduler': java.lang.NullPointerException [See nested exception: java.lang.NullPointerException]
at org.quartz.impl.jdbcjobstore.JobStoreCMT.getNonManagedTXConnection(JobStoreCMT.java:170)
at org.quartz.impl.jdbcjobstore.JobStoreSupport.doRecoverMisfires(JobStoreSupport.java:3107)
at org.quartz.impl.jdbcjobstore.JobStoreSupport$MisfireHandler.manage(JobStoreSupport.java:3896)
at org.quartz.impl.jdbcjobstore.JobStoreSupport$MisfireHandler.run(JobStoreSupport.java:3916)
Caused by: java.lang.NullPointerException
at org.quartz.impl.jdbcjobstore.JobStoreCMT.getNonManagedTXConnection(JobStoreCMT.java:162)
... 3 more
17:31:35,049 INFO [STDOUT] 2012-02-23 17:31:35 ClassPathXmlApplicationContext [INFO] Bean 'contractTemplateCategoryDAO' is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
17:31:35,102 INFO [STDOUT] 2012-02-23 17:31:35 ClassPathXmlApplicationContext [INFO] Bean 'contractTemplateParamDAO' is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
Please help me.