Sun Microsystems 820434310 Server User Manual


 
Pre-fetching generally improves performance because it reduces the number of database
accesses. However, if the business logic often uses Orders without referencing their OrderLines,
then this can have a performance penalty, that is, the system has spent the eort to pre-fetch the
OrderLines that are not actually needed.
Avoid pre-fetching for specic nder methods; this can often avoid that penalty. For example,
consider an order bean has two nder methods: a findByPrimaryKey method that uses the
orderlines, and a findByCustomerId method that returns only order information and hence
doesn’t use the orderlines. If you’ve enabled CMR pre-fetching for the orderlines, both nder
methods will pre-fetch the orderlines. However, you can prevent pre-fetching for the
findByCustomerId method by including this information in the sun-ejb-jar.xml descriptor:
<ejb>
<ejb-name>OrderBean</ejb-name>
...
<cmp>
<prefetch-disabled>
<query-method>
<method-name>findByCustomerId</method-name>
</query-method>
</prefetch-disabled>
</cmp>
</ejb>
JDBC and Database Access
Here are some tips to improve the performance of database access.
Use JDBC Directly
When dealing with large amounts of data, such as searching a large database, use JDBC directly
rather than using Entity EJB components.
Encapsulate Business Logic in Entity EJB Components
Combine business logic with the Entity EJB component that holds the data needed for that logic
to process.
Close Connections
To ensure that connections are returned to the pool, always close the connections after use.
Minimize the DatabaseTransaction Isolation Level
Use the default isolation level provided by the JDBC driver rather than calling
setTransactionIsolationLevel(), unless you are certain that your application behaves
correctly and performs better at a dierent isolation level.
EJB PerformanceTuning
SunGlassFishEnterpriseServer2.1PerformanceTuningGuide January200946