WebSphere Application Server - Express, Version 6.0.x     Operating Systems: AIX, HP-UX, Linux, Solaris, Windows

Using startup beans

Why and when to perform this task

A startup bean is a session bean that is loaded when an application starts. Startup beans enable Java 2 Platform Enterprise Edition (J2EE) applications to run business logic automatically, whenever an application starts or stops normally.

Startup beans are especially useful when used with asynchronous bean features. For example, a startup bean might create an alarm object that uses the Java Message Service (JMS) to periodically publish heartbeat messages on a well-known topic. This enables clients or other server applications to determine whether the application is available.

Steps for this task

  1. Use the home interface, com.ibm.websphere.startupservice.AppStartUpHome, to designate a bean as a startup bean.
  2. Use the remote interface, com.ibm.websphere.startupservice.AppStartUp, to define start() and stop() methods on the bean.

    The startup bean start() method is called when the application starts and contains business logic to be run at application start time.

    The start() method returns a boolean value. True indicates that the business logic within the start() method ran successfully. Conversely, False indicates that the business logic within the start() method failed to run completely. A return value of False also indicates to the Application server that application startup is aborted.

    The startup bean stop() method is called when the application stops and contains business logic to be run at application stop time. Any exception thrown by a stop() method is logged only. No other action is taken.

    The start() and stop() methods must never use the TX_MANDATORY transaction attribute. A global transaction does not exist on the thread when the start() or stop() methods are invoked. Any other TX_* attribute can be used. If TX_MANDATORY is used, an exception is logged, and the application start is aborted.

    The start() and stop() methods on the remote interface use Run-As mode. Run-As mode specifies the credential information to be used by the security service to determine the permissions that a principal has on various resources. If security is on, the Run-As mode needs to be defined on all of the methods called. The identity of the bean without this setting is undefined.

    There are no restrictions on what code the start() and stop() methods can run, since the full Application Server programming model is available to these methods.

  3. Use an optional environment property integer, wasStartupPriority, to specify the start order of multiple startup beans in the same Java Archive (JAR) file. If the environment property is found and is the wrong type, application startup is aborted. If no priority value is specified, a default priority of 0 is used. It is recommended that you specify the priority property. Beans that have specified a priority are sorted using this property. Beans with numerically lower priorities are run first. Beans that have the same priority are run in an undefined order. Beans are stopped in the opposite order to their start priority.

What to do next

View the startup beans service settings.



Sub-topics
Enabling startup beans in the administrative console
Startup beans service settings

Related tasks
Using asynchronous beans

Task topic    

Terms of Use | Feedback

Last updated: Jun 8, 2005 12:45:23 PM EDT
http://publib.boulder.ibm.com/infocenter/wasinfo/v6r0/index.jsp?topic=/com.ibm.websphere.express.doc/info/exp/asyncbns/tasks/tasb_confstb.html

© Copyright IBM Corporation 2002, 2005. All Rights Reserved.
This information center is powered by Eclipse technology. (http://www.eclipse.org)