• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Application Level Initialization

 
Ranch Hand
Posts: 211
Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 10445
227
IntelliJ IDE Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 211
Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 211
Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic