Package com.ibm.websphere.startupservice

Provides for applications having business logic invoked when an application is started or stopped.

See:
          Description

Interface Summary
AppStartUp Startup beans must use this interface for their remote interfaces.
AppStartUpHome Any startup beans must use this interface in their J2EE descriptors.
 

Package com.ibm.websphere.startupservice Description

Provides for applications having business logic invoked when an application is started or stopped.

Required jars

Applications that use these APIs must have the startupbean.jar on their classpath. This is located in the lib directory of a WAS-E 5.0 installation.

Startup beans

A startup bean is a stateless or stateful session bean. These beans must use com.ibm.websphere.startupservice.AppStartUpHome as its home interface and com.ibm.websphere.startupservice.AppStartUp as the remote interface. These must be used and cannot be extended. The AppStartUp remote interface has two methods, start and stop. Both methods can be any TX_ attribute except for TX_MANDATORY. It is also acceptable if the bean uses bean managed transactions. In this case, then any TX_ attribute in these methods is ignored.

An ejb jar in an EAR may contain zero or more of these startup beans. When an application is started then WebSphere will find any session beans that specified the AppStartUpHome and AppStartUp interfaces. The start method on these beans is then called. The start method returns a boolean. If the method returns true then the application start proceeds normally. If it returns false then the application start process fails. If the start method throws any exception then the application start process fails also.

When the application is stopped then the stop methods on those beans is invoked. This happens the reverse order to the start methods being invoked. If the JVM stops suddenly then the stop methods will not be invoked. Any exceptions thrown by a stop method are ignored.

Influencing the execution order of startup beans within an ejb-jar

EJBs can have one or more properties associated with them. These properties are normally accessing using JNDI from the java:comp/env/xxx space. If a startup bean has an integer property named "wasStartupPriority" is present then this can be used to specify a priority. If a bean does not have this property then it defaults to 0 for that bean.

The beans are started in numerically ascending order and are stopped in numerically descending order.

Using startup beans in a clustered application in a distributed environment.

If a startup bean is present in a clustered application, the start and stop methods are called whenever a cluster member starts or stops. For example, if App A has a startup bean and is deployed to a cluster of four machines numbered 1 through 4. The following events may occur:
EventWhat happens
Cluster member on machine #1 startsThe app startup bean start method is executed on machine #1.
Cluster member on machine #2 startsThe app startup bean start method is executed on machine #2.
Cluster member on machine #3 startsThe app startup bean start method is executed on machine #3.
Cluster member on machine #1 stopsThe app startup bean stop method is executed on machine #1.
Cluster member on machine #1 restartsThe app startup bean start method is executed on machine #1.
Cluster member on machine #4 startsThe app startup bean start method is executed on machine #4.
Therefore, 'start' and 'stop' are actions that occur for each cluster member. Start and stop methods can be called while a clustered application is already running.

If a clustered application needs to execute startup code ONE time before the first cluster member starts then it is best to execute a script that invokes a session bean that contains the start/stop logic. Execute this script prior to starting the clustered application. Likewise, before you stop the clustered application then run another script to execute the application stop code and then shutdown the application. It may be necessary to factor the application into two pieces;

This would allow the 'running code' application to be stopped and then the script can invoke code in the 'start/stop' application. Likewise, at startup then start the 'start/stop' application first, run the script then start the 'running code' application.

Security

If security is on then the start and stop methods must run as a role.

Best practices

The start method should execute quickly. These methods must complete in order for the application to start successfully. This means that if a start method takes a long time to execute then the application won't start quickly. It will delay the application becoming available. A start method that needs to do expensive processing should use a WorkManager and a Work to spin off the work to another thread so that the application can start in parallel with the expensive operation.