Initialization for EJB
2 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   alvin_chin
Posted On:   Thursday, January 23, 2003 08:44 PM

I have a server that contains an EJB container and contains an EJB which I have deployed. I want to be able to call some initialization routines before the first client calls the create() method to get a new instance of the EJB. This EJB is acting as a server, what I want to do is initialize some tables which will be shared by all EJB clients. How would I go about doing this? In the EJB Bean itself, I see a whole bunch of methods ejbCreate , ejbPassivate , ejbActivate and ejbRemove for the lifecycle of a stateful EJB. But I don't want to do initialization of the tables in the create() method otherwise every time a client connects to the EJB, it will create a new instance and hence the tables wil   More>>

I have a server that contains an EJB container and contains an EJB which I have deployed. I want to be able to call some initialization routines before the first client calls the create() method to get a new instance of the EJB. This EJB is acting as a server, what I want to do is initialize some tables which will be shared by all EJB clients.



How would I go about doing this? In the EJB Bean itself, I see a whole bunch of methods ejbCreate , ejbPassivate , ejbActivate and ejbRemove for the lifecycle of a stateful EJB. But I don't want to do initialization of the tables in the create() method otherwise every time a client connects to the EJB, it will create a new instance and hence the tables will get reinitialized again.



Any ideas? Can this be done? Or should I not be using an EJB for this?



Thanks.    <<Less

Re: Initialization for EJB

Posted By:   dipankar_datta  
Posted On:   Thursday, January 23, 2003 11:16 PM


I think you should write the initialization codes in a normal class & set this class as a server startup class
so that all initialization activities are performed at server startup.

This thing from session beans ...well may be you will keep a flag obj (Boolean) telling you whether tables are initialized or not in some predefined JNDI location.Inside create() lookup for that flag & if it is false then do the required things & set the flag to true.In future all
create() will thus be able to skip the initialization process by seeing the flag val.But this is definatly a bad design...leads to unnecessary lookup overhead.

Re: Initialization for EJB

Posted By:   dipankar_datta  
Posted On:   Thursday, January 23, 2003 11:16 PM


I think you should write the initialization codes in a normal class & set this class as a server startup class
so that all initialization activities are performed at server startup.

This thing from session beans ...well may be you will keep a flag obj (Boolean) telling you whether tables are initialized or not in some predefined JNDI location.Inside create() lookup for that flag & if it is false then do the required things & set the flag to true.In future all
create() will thus be able to skip the initialization process by seeing the flag val.But this is definatly a bad design...leads to unnecessary lookup overhead.

About | Sitemap | Contact