This synchronous report generation strategy was found wanting in some midsize to
large companies where eInsure was installed. As these companies used this application
to add new products, policies, parties, and claims, the data volume increased at a rapid
pace. This led to frustrating user experiences because the synchronous reports mostly
timed out with the large data volume. The users were already frustrated because of the
blocking nature of the synchronous reports. Most reports generated large data sets, and
transferring this data from the database to the application server and subsequently to the
client browser clogged the network.
• Applications need to support long-running use cases.
• It is necessary to execute the business services asynchronously.
• Long-running operations should not block users.
Use a service activator to receive and carry out an asynchronous service request.
Strategies with the Spring Framework
You can solve the blocking problem discussed earlier by allowing the actual report gener-
ation service request to be handled asynchronously. JMS message listeners can be
applied to process this business request asynchronously. However, a more robust
approach would be to use a message-driven bean (MDB). This is because MDBs combine
the asynchronous behavior of the message listener with services provided by the EJB
Spring provides support for building MDBs as well as sending messages to a JMS
queue or topic. Just like stateless session beans, Spring also provides convenient base
classes to develop MDBs, as shown in Figure 5-3. The root of the class hierarchy is the
AbstractEnterpriseBean class, which can be used to load a Spring application context.
The subclass AbstractMessageDrivenBean is the convenient class for developing MDBs.
The setMessageDrivenContext is used to save the MessageDrivenContext object supplied by
the EJB container. The subclasses can override the onEjbCreate method for the initializing
or loading of any bean from the Spring application context associated with the MDB. The
AbstractJmsMessageDrivenBean implements the MessageListener interface, thus making
MDBs compatible with JMS messages.