aspose file tools*
The moose likes Spring and the fly likes Scheduling job. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Scheduling job." Watch "Scheduling job." New topic
Author

Scheduling job.

kunal green
Greenhorn

Joined: Dec 31, 2009
Posts: 26

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.
Vicky Vijay
Ranch Hand

Joined: Apr 23, 2008
Posts: 125
ApplicationContext appCtx = new ClassPathXmlApplicationContext("WEB-INF/classes/applicationContext.xml");


I hope... the path provided in ClassPathXmlApplicationContext(..) is wrong...

Try using



hope this helps.. !


Refer the below site,

http://www.java2s.com/Code/Java/Spring/LoadconfigfilefromClassPath.htm
Saifuddin Merchant
Ranch Hand

Joined: Feb 08, 2009
Posts: 597

Also please do use code tags when posting any code. Make it a lot easier to read and understand the question.


Cheers - Sam.
Twisters - The new age Java Quiz || My Blog
kunal green
Greenhorn

Joined: Dec 31, 2009
Posts: 26

i am able to get my beans .
But when i am accessing the db i am getting empty resultset and getting index out of bound exception when iterating through it.
Vicky Vijay
Ranch Hand

Joined: Apr 23, 2008
Posts: 125
Kunal,

As you have not provided enough information,

I presume that,

1. You are able to get the Beans

2. You are able to invoke the "SimpleQuartzJob.class",

but you are not able to get the resultset ??


Check the following,


Are you able to ESTABLISH the Database Connectivity,

If Yes,

Are you using any where Clause in the SELECT Query

If Yes... Check whether the Input param has been obtained correctly

If No, Check whether the table contains at-least one records ?




 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Scheduling job.
 
Similar Threads
scheduler
Scheduler Task in Java
Quartz/Timer question with ejb3
which on one is right choice for task scheduling ?
Job Scheduling - EJB Timer Service vs Quartz Scheduler