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