Server User Manual
Table Of Contents
- Sun GlassFish Enterprise Server 2.1 Performance Tuning Guide
- Preface
- Overview of Enterprise Server Performance Tuning
- Tuning Your Application
- Java Programming Guidelines
- Java Server Page and Servlet Tuning
- EJB Performance Tuning
- Goals
- Monitoring EJB Components
- General Guidelines
- Using Local and Remote Interfaces
- Improving Performance of EJB Transactions
- Use Container-Managed Transactions
- Don’t Encompass User Input Time
- Identify Non-Transactional Methods
- Use TX_REQUIRED for Long Transaction Chains
- Use Lowest Cost Database Locking
- Use XA-Capable Data Sources Only When Needed
- Configure JDBC Resources as One-Phase Commit Resources
- Use the Least Expensive Transaction Attribute
- Using Special Techniques
- Tuning Tips for Specific Types of EJB Components
- JDBC and Database Access
- Tuning Message-Driven Beans
- Tuning the Enterprise Server
- Deployment Settings
- Logger Settings
- Web Container Settings
- EJB Container Settings
- Java Message Service Settings
- Transaction Service Settings
- HTTP Service Settings
- ORB Settings
- Thread Pool Settings
- Resources
- Tuning the Java Runtime System
- Tuning the Operating System and Platform
- Tuning for High-Availability
- Index

■
Database rows represented by the bean do not change.
■
The application can tolerate using out-of-date values for the bean.
For example, an application might use a read-only bean to represent a list of best-seller books.
Although the list might change occasionally in the database (say, from another bean entirely),
the change need not be reected immediately in an application.
The ejbLoad() method of a read-only bean is handled dierently for CMP and BMP beans. For
CMP beans, the EJB container calls ejbLoad() only once to load the data from the database;
subsequent uses of the bean just copy that data. For BMP beans, the EJB container calls
ejbLoad() the rst time a bean is used in a transaction. Subsequent uses of that bean within the
transaction use the same values. The container calls ejbLoad() for a BMP bean that doesn’t run
within a transaction every time the bean is used. Therefore, read-only BMP beans still make a
number of calls to the database.
To create a read-only bean, add the following to the EJB deployment descriptor
sun-ejb-jar.xml:
<is-read-only-bean>true</is-read-only-bean>
<refresh-period-in-seconds>600</refresh-period-in-seconds>
Refresh period
An important parameter for tuning read-only beans is the refresh period, represented by the
deployment descriptor entity refresh-period-in-seconds. For CMP beans, the rst access to
a bean loads the bean’s state. The rst access after the refresh period reloads the data from the
database. All subsequent uses of the bean uses the newly refreshed data (until another refresh
period elapses). For BMP beans, an ejbLoad() method within an existing transaction uses the
cached data unless the refresh period has expired (in which case, the container calls ejbLoad()
again).
This parameter enables the EJB component to periodically refresh its “snapshot” of the database
values it represents. If the refresh period is less than or equal to 0, the bean is never refreshed
from the database (the default behavior if no refresh period is given).
Pre-fetching Container Managed Relationship (CMR) Beans
If a container-managed relationship (CMR) exists in your application, loading one bean will
load all its related beans. The canonical example of CMR is an order-orderline relationship
where you have one Order EJB component that has related OrderLine EJB components. In
previous releases of the application server, to use all those beans would require multiple
database queries: one for the Order bean and one for each of the OrderLine beans in the
relationship.
In general, if a bean has n relationships, using all the data of the bean would require n+1
database accesses. Use CMR pre-fetching to retrieve all the data for the bean and all its related
beans in one database access.
EJB PerformanceTuning
Sun GlassFish Enterprise Server 2.1 Performance Tuning Guide • January 200944










