dcsimg
Accessing a database table in case of a scheduled task criteria is reached
2 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Erkan_Ozkan
Posted On:   Monday, August 23, 2004 01:34 AM

Hi, I am developing a dynamic web application which runs on WebSphere Application Server Version 5. I am using a Timer thread from java.util.Timer class, and schedule a task by using a (java.util.TimerTask) TimerTask object, which is of class RemindTask as follows: ... private static Timer timer ; ... if(timer == null) timer = new Timer() ; ... Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.HOUR_OF_DAY, 9); calendar.set(Calendar.MINUTE, 35); calendar.set(Calendar.SECOND, 0); Date time = calendar.getTime(); timer.scheduleAtFi   More>>

Hi,

I am developing a dynamic web application which runs on WebSphere Application Server Version 5.

I am using a Timer thread from java.util.Timer class,
and schedule a task by using a (java.util.TimerTask)
TimerTask object, which is of class RemindTask as follows:





			
...
private static Timer timer ;
...

if(timer == null)

timer = new Timer() ;


...

Calendar calendar = Calendar.getInstance();

calendar.set(Calendar.HOUR_OF_DAY, 9);

calendar.set(Calendar.MINUTE, 35);

calendar.set(Calendar.SECOND, 0);

Date time = calendar.getTime();

timer.scheduleAtFixedRate(new RemindTask() , time , 5000);

...










In the "run" method of RemindTask class
(RemindTask class is extended from TimerTask class),
I want to access to a datasource and insert data into
a table in a database. But when my persistance

object try to get a connection from database,
the following error occurs :






			
Connection to pool failed(Databean) - javax.naming.NameNotFoundException: Name comp/env/jdbc not found in context "java:".


[23.08.2004 09:52:26:219 EEST] 25fd8c1b SystemErr R java.lang.NullPointerException

[23.08.2004 09:52:26:219 EEST] 25fd8c1b SystemErr R at com.flyalex58.persistence.Persister.save(Persister.java:923)










It seems to me that, I can' t reach my datasource
from a TimerTask extended class, I mean, my

persistance object cannot read datasource info
from my application context. Has anybody idea about

this problem? Much thanks ...





//Erkan    <<Less

Re: Accessing a database table in case of a scheduled task criteria is reached

Posted By:   Anonymous  
Posted On:   Sunday, September 5, 2004 08:54 PM

That's because it seems from your code you are creating your own threads, and they are not managed by the WAS environment, and so do not have a J2EE context.

Since you are using WAS take a look at the JavaDoc for com.ibm.websphere.scheduler. Or you can implement your own by implementing


com.ibm.websphere.asynchBeans.Work
interface.

Re: Accessing a database table in case of a scheduled task criteria is reached

Posted By:   Edward_Harned  
Posted On:   Monday, August 23, 2004 06:41 AM

If you post the relevant code -- FORMATTED so we can read it easily -- then perhaps we can find the problem.


You're probably getting a connection and not keeping the reference alive.

About | Sitemap | Contact