WebSphere Application Server and Module Lifecycle Options
 Technote (troubleshooting)
 
Problem(Abstract)
IBM® WebSphere® Application Server provides two programming models for tying J2EE™ application business logic to the lifecycle of an application or application module.

Startup Beans is a proprietary Application Server service that calls Enterprise JavaBeans™ methods when the application or Enterprise JavaBeans module starts and stops. The Servlet specification also provides two lifecycle callback operations.

This article provides a high-level comparison between Startup Beans and the Servlet specification.
 
Resolving the problem
Startup Beans Servlet Initialization
Scope: Application (EAR) or Enterprise JavaBean Module (JAR) Servlet or WAR
Purpose: Running J2EE application business logic at application and/or Enterprise JavaBean Module start/stop time.

Note: Enterprise JavaBean module startup beans are not available in 5.0 or 5.1.

Running Servlet code at Servlet or Web Module (WAR) start/stop time.
Administration: WebSphere Assembly Toolkit, Application Server Toolkit for WebSphere Application Server, WebSphere Application Developer, Rational® Application Developer or manual deployment descriptor editor. WebSphere Assembly Toolkit, Application Server Toolkit for WebSphere Application Server, WebSphere Application Developer, Rational Application Developer or manual deployment descriptor editor.
Implementation: Session bean with specific remote and home interfaces:
  • com.ibm.websphere.startupservice.AppStartUp
  • com.ibm.websphere.startupservice.AppStartUpHome
  • com.ibm.websphere.startupservice.ModStartUp
  • com.ibm.websphere.startupservice.ModStartUpHome
Any Servlet or a ServletContextListener.
Differences: AppStartUp.start() is triggered when an application is started.

AppStartUp.stop() is triggered when an application is stopping or when the application server is stopping, whichever is first.

ModStartUp.start() is triggered when an Enterprise JavaBean module is started. The ordering of the modules can be controlled using the "Starting weight" value for each module in an EAR.

ModStartUp.stop() is triggered when the EJB module is stopping. An EJB module is stopped when the application or application server is stopped.

Servlet.init() is triggered during Servlet load time. Servlets are loaded when used or when the Load-on-Startup attribute is set.

Servlet.destroy() is triggered during Servlet destroy time that can happen whenever the container needs to free resources.

Application Server currently destroys the Servlet only when the web module is unloaded.

ServletContextListener.contextInitialized() is triggered when a web module is loaded.

ServletContextListener.contextDestroyed() is triggered when a web module is unloaded.

The ordering of the modules can be controlled using the "Starting weight" value for each module in an EAR.

Startup beans can be ordered within an application and module using the optional “wasStartupPriority” java.lang.Integer env entry in the ejb-jar.xml. The startup priority is scoped to the module or application. Module start/stop methods are always run before the associated application start/stop methods are run. Servlet initialization can be ordered using the <load-on-startup> attribute. ServletContextListeners can be ordered based on their position in the web.xml.
When a start() method returns false, the entire application is prohibited from starting. Startup beans already started are stopped in reverse order. Servlets that throw a UnavailableException to prevent the Servlet from initializing. Other servlets, modules and applications are unaffected.
All EJB bean and container transaction types except for Mandatory are supported. User transactions are supported.
Threading supported using Asynchronous Beans or CommonJ WorkManager. Threading supported using Asynchronous Beans or CommonJ WorkManager.
When to use: Ideal for application-level initialization. Ideal for Servlet or Web Module initialization.
Limitations: All startup events in an application are serialized. All startup events in an application are serialized.
Startup Beans startup occurs after all modules are loaded. This means Enterprise JavaBeans can accept requests before startup beans are executed. Lifecycle not tied to application; therefore dependant modules may not be started.
Only handles per-server application initialization. Clustered application initialization needs to be handled using scripts. Only handles per-server application initialization. Clustered application initialization needs to be handled using scripts.
 
 
Cross Reference information
Segment Product Component Platform Version Edition
Application Servers Runtimes for Java Technology Java SDK
 
 


Document Information


Product categories: Software > Application Servers > Distributed Application & Web Servers > WebSphere Application Server
Operating system(s): z/OS
Software version: 6.1
Software edition:
Reference #: 1236342
IBM Group: Software Group
Modified date: Apr 25, 2006