• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Application server start/stop event

 
Genie May
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How to catch application server start/stop(shutdown) event into java code?
 
Pradeep bhatt
Ranch Hand
Posts: 8933
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Is there common interface(given by specification J2EE) for it actions?

Thank you!
 
Pradeep bhatt
Ranch Hand
Posts: 8933
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • 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.
 
Chris Mathews
Ranch Hand
Posts: 2712
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Thanks for answer!

At the time of application server shutdown contextDestroyed() method will be invoked?
 
gao zhixin
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • 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: 2712
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic