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

Suggested Coding Practices
This section provides some tips on coding practices that improve servlet and JSP application
performance.
General Guidelines
Follow these general guidelines to increase performance of the presentation tier:
■
Minimize Java synchronization in servlets.
■
Don’t use the single thread model for servlets.
■
Use the servlet’s init() method to perform expensive one-time initialization.
■
Avoid using System.out.println() calls.
Avoid Shared Modied Class Variables
In the servlet multithread model (the default), a single instance of a servlet is created for each
application server instance. All requests for a servlet on that application instance share the same
servlet instance. This can lead to thread contention if there are synchronization blocks in the
servlet code. So, avoid using shared modied class variables, since they create the need for
synchronization.
HTTP Session Handling
Follow these guidelines when using HTTP sessions:
■
Create sessions sparingly. Session creation is not free. If a session is not required, do not
create one.
■
Use javax.servlet.http.HttpSession.invalidate() to release sessions when they are
no longer needed.
■
Keep session size small, to reduce response times. If possible, keep session size below seven
KB.
■
Use the directive <%page session="false"%> in JSP les to prevent the Enterprise Server
from automatically creating sessions when they are not necessary.
■
Avoid large object graphs in an HttpSession . They force serialization and add
computational overhead. Generally, do not store large objects as HttpSession variables.
■
Don’t cache transaction data in HttpSession. Access to data in an HttpSession is not
transactional. Do not use it as a cache of transactional data, which is better kept in the
database and accessed using entity beans. Transactions will rollback upon failures to their
original state. However, stale and inaccurate data may remain in HttpSession objects. The
Enterprise Server provides “read-only” bean-managed persistence entity beans for cached
access to read-only data.
Java Server Page and ServletTuning
Sun GlassFish Enterprise Server 2.1 Performance Tuning Guide • January 200930










