Win a copy of Pro Spring MVC with WebFlux: Web Development in Spring Framework 5 and Spring Boot 2 this week in the Spring forum!
  • 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
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Bear Bibeault
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh

Application server start/stop event

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How to catch application server start/stop(shutdown) event into java code?
 
Ranch Hand
Posts: 8944
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Some app servers(Weblogic,Oracle,JBoss) provide Startup and Shutdown classes. May be this would help you.
 
Genie May
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is there common interface(given by specification J2EE) for it actions?

Thank you!
 
Pradeep bhatt
Ranch Hand
Posts: 8944
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Genie May:
Is there common interface(given by specification J2EE) for it actions?

Thank you!



No. The spec does not talk about it.
 
Ranch Hand
Posts: 2713
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The J2EE Specification doesn't define Application Server startup lifecycle events, however there are a couple standard ways this is done without restorting to vendor specific apis...

1. Use a ServletContextListener and implement your startup code in the contextInitialized() method.

2. Use a "startup servlet", which is basically just a Servlet with its load-on-startup value set to 0. Implement your startup code in the servlet's init() method.

The "better" solution of the two is #1, however it requires a Servlet 2.3 or higher container and, since load order isn't defined in the spec, you should check to make sure your container initializes listeners before servlets.

* WebLogic and Oracle Application Servers in the past initialized Servlets before Listeners. This behavior might have changed with the latest releases.
 
Genie May
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for answer!

At the time of application server shutdown contextDestroyed() method will be invoked?
 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think Servlet only used in Web Container, if you don't use a Web frontier, the problem can't solve. But I'm newbie in J2EE, so all upstairs can ignore my post...
 
Chris Mathews
Ranch Hand
Posts: 2713
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sure, but if you are deploying an EJB solution you are most likely going to deploy as an Enterprise Archive (EAR). Ears support both ejb and war components, very simple to drop in a war for the purpose of providing some startup logic.
 
reply
    Bookmark Topic Watch Topic
  • New Topic