[ Bottom of Page | Previous Page | Next Page | Contents | Index | Library Home |
Legal |
Search ]
Performance Management Guide
Java Performance Guidelines
The following are basic Java performance issues:
- Use StringBuffer instead of string concatenations,
when doing excessive string manipulations to avoid unnecessarily creating
objects that eventually must undergo garbage collection.
- Avoid excessive writing to the Java console to reduce the cost of string
manipulations, text formatting, and output.
- Avoid the costs of object creation and manipulation by using primitive
types for variables when necessary.
- Cache frequently used objects to reduce the amount of garbage collection
needed, and avoid the need to repeatedly create the objects.
- Group native operations to reduce the number of Java Native Interface
(JNI) calls when possible.
- Use synchronized methods only when necessary, to limit the multitasking
in the JVM and operating system.
- Avoid invoking the garbage collector unless necessary. If you must invoke
it, do so only during idle time or some noncritical phase.
- Use int instead of long whenever
possible, because 32-bit operations are executed faster than 64-bit.
- Declare methods as final whenever possible. Final methods are handled
better by the JVM.
- Use the key word static final when creating constants
in order to reduce the number of times the variables need to be initialized.
- Avoid unnecessary "casts" and "instanceof" references because casting
in Java is not done at compile time but at run time.
- Avoid the use of vectors whenever possible when an array will suffice.
- Add and delete items from the end of the vector for better performance.
- Compile Java files with the -O option.
- Avoid allocating objects within loops.
- Use buffer I/O and tune the buffer size.
- Use connection pools and cached-prepared statements for database access.
- Use connection pools to the database and reuse connections rather than
repeatedly opening and closing connections.
- Maximize thread lifetimes and minimize thread creation and destruction
cycles.
- Minimize contention for shared resources.
- Minimize creation of short lived objects.
- Avoid remote method calls.
- Use callbacks to avoid blocking remote method calls.
- Avoid creating an object that would only be used for accessing a method.
- Whenever possible, keep synchronized methods out of loops.
- Store string and char data as Unicode in the database.
- Reorder CLASSPATH so that the most used libraries occur first.
[ Top of Page | Previous Page | Next Page | Contents | Index | Library Home |
Legal |
Search ]