Using startup beans

Why and when to perform this task

[5.0 only][Version 5.0.1][Version 5.0.2]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 execute business logic automatically, whenever an application starts or stops normally.

Startup beans are especially useful when used in with asynchronous bean features. For example, a startup bean might create an alarm object that uses Java Messaging 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. [5.0 only][Version 5.0.1][Version 5.0.2]Use the home interface, com.ibm.websphere.startupservice.AppStartUpHome, to designate a bean as a startup bean
  2. [5.0 only][Version 5.0.1][Version 5.0.2]Use the remote interface, com.ibm.websphere.startupservice.AppStartUp, to define a start() and stop() method on the bean.

    The startup bean start() method is called when the application starts. The startup bean implements any business logic that must run at application start time.

    The start() method returns a boolean. True indicates normal application startup and false indicates that the application start process should be aborted. The start() and stop() methods should not use a TX_MANDATORY attribute because there never is a transaction 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 (need a transaction for mandatory) and the application does not start.

    The startup bean stop() method is called when the application stops and implements any business logic that needs to run. Any exception thrown by a stop() method is ignored, but logged to trace.

    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 Enterprise 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 executed first. Beans that have the same priority are executed in an undefined order. All priorities must be positive integers. The priority is used to order beans within an enterprise bean JAR file. The order in which this process happens is applied to different enterprise bean JAR files in a single EAR file is undefined. Beans are stopped in the opposite order to their start priority.

Related tasks
Using asynchronous beans



Searchable topic ID:   tasb_confstb
Last updated: Jun 21, 2007 8:07:48 PM CDT    WebSphere Business Integration Server Foundation, Version 5.0.2
http://publib.boulder.ibm.com/infocenter/wasinfo/index.jsp?topic=/com.ibm.wasee.doc/info/ee/asyncbns/tasks/tasb_confstb.html

Library | Support | Terms of Use | Feedback