GeeCON Prague 2014*
The moose likes EJB and other Java EE Technologies and the fly likes Application server start/stop  event 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 server start/stop  event" Watch "Application server start/stop  event" New topic
Author

Application server start/stop event

Genie May
Greenhorn

Joined: Apr 06, 2006
Posts: 4
How to catch application server start/stop(shutdown) event into java code?
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8919

Some app servers(Weblogic,Oracle,JBoss) provide Startup and Shutdown classes. May be this would help you.


Groovy
Genie May
Greenhorn

Joined: Apr 06, 2006
Posts: 4
Is there common interface(given by specification J2EE) for it actions?

Thank you!
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8919

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

Joined: Jul 18, 2001
Posts: 2712
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

Joined: Apr 06, 2006
Posts: 4
Thanks for answer!

At the time of application server shutdown contextDestroyed() method will be invoked?
gao zhixin
Ranch Hand

Joined: Jan 18, 2006
Posts: 42
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

Joined: Jul 18, 2001
Posts: 2712
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.
 
GeeCON Prague 2014
 
subject: Application server start/stop event