Sun Microsystems 820434310 Server User Manual


 
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 reected immediately in an application.
The ejbLoad() method of a read-only bean is handled dierently 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’sstate. 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
SunGlassFishEnterpriseServer2.1PerformanceTuningGuide January200944