 |
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. |