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

String str = "testing";
str = str + "abc";
The compiler translates this code as:
String str = "testing";
StringBuffer tmp = new StringBuffer(str);
tmp.append("abc");
str = tmp.toString();
Therefore, copying is inherently expensive and overusing it can reduce performance
signicantly.
Assign null to Variables That Are No Longer Needed
Explicitly assigning a null value to variables that are no longer needed helps the garbage
collector to identify the parts of memory that can be safely reclaimed. Although Java provides
memory management, it does not prevent memory leaks or using excessive amounts of
memory.
An application may induce memory leaks by not releasing object references. Doing so prevents
the Java garbage collector from reclaiming those objects, and results in increasing amounts of
memory being used. Explicitly nullifying references to variables after their use allows the
garbage collector to reclaim memory.
One way to detect memory leaks is to employ proling tools and take memory snapshots after
each transaction. A leak-free application in steady state will show a steady active heap memory
after garbage collections.
Declare Methods as nal Only If Necessary
Modern optimizing dynamic compilers can perform inlining and other inter-procedural
optimizations, even if Java methods are not declared final. Use the keyword final as it was
originally intended: for program architecture reasons and maintainability.
Only if you are absolutely certain that a method must not be overridden, use the final
keyword.
Declare Constants as static nal
The dynamic compiler can perform some constant folding optimizations easily, when you
declare constants as static final variables.
Avoid Finalizers
Adding nalizers to code makes the garbage collector more expensive and unpredictable. The
virtual machine does not guarantee the time at which nalizers are run. Finalizers may not
always be executed, before the program exits. Releasing critical resources in finalize()
methods may lead to unpredictable application behavior.
Java Programming Guidelines
Sun GlassFish Enterprise Server 2.1 Performance Tuning Guide • January 200928










