File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes EJB and other Java EE Technologies and the fly likes Application Level Initialization Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Application Level Initialization" Watch "Application Level Initialization" New topic
Author

Application Level Initialization

Sagar Shroff
Ranch Hand

Joined: Jun 07, 2011
Posts: 208

Hello ranchers,
I am facing an issue in my design of my application and struggling to get a robust solution for it.
To lay it down in simple terms i have an EAR which has currently 1 war and 1 ejb jar. I am expecting my EAR to scale up in near time,
where i will be having few more wars and business components added. Currently i am using a ServletContextListener to do all the application level initialization.
But then later noticed that it is not a correct solution as i don't want to depend on sequence of servlet's startups (from different wars).
There should be some standardized solution which allows me to do initialization at application level. In simple terms i want to execute some piece of code(at EAR level)
before any other code gets executed.


Regards,
Shroff.


OCJP-90%,OCPWCD-95%
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10213
    
166

Sagar Shroff wrote:
But then later noticed that it is not a correct solution as i don't want to depend on sequence of servlet's startups (from different wars).


You can use initialize-in-order within the application.xml and then list the war modules in the right order and have the initialization done in the first listed war.

[My Blog] [JavaRanch Journal]
Sagar Shroff
Ranch Hand

Joined: Jun 07, 2011
Posts: 208

Jaikiran Pai wrote:
You can use initialize-in-order within the application.xml and then list the war modules in the right order and have the initialization done in the first listed war.

Yeah thats what i am backing on currently, just wanted to know if this is the only standard way ?


Regards,
Shroff.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19723
    
  20

How about a bean annotated with @Singleton and @Startup? You still don't have full control over the startup order if you use other mechanisms (like ServletContextListener), but at least you can use @DependsOn to specify that these beans should be loaded after another. For instance:
You can now know for sure that these three beans are loaded at startup in order MyBean1, MyBean2, MyBean3.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Sagar Shroff
Ranch Hand

Joined: Jun 07, 2011
Posts: 208

Rob Spoor wrote:How about a bean annotated with @Singleton and @Startup? You still don't have full control over the startup order if you use other mechanisms (like ServletContextListener), but at least you can use @DependsOn to specify that these beans should be loaded after another.


Thanks. Actually i was trying to figure out whether there is any way i can achieve to put all my initialization code in ear project. But then reading through articles i realized that ear core objective is packaging of application.


Regards,
Shroff.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Application Level Initialization