• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

Application Level Initialization  RSS feed

 
Ranch Hand
Posts: 209
Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Sheriff
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
 
Sagar Shroff
Ranch Hand
Posts: 209
Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
 
Sheriff
Posts: 21449
95
Chrome Eclipse IDE Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Sagar Shroff
Ranch Hand
Posts: 209
Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!