Académique Documents
Professionnel Documents
Culture Documents
Use static variables for fields that only need to be assigned once
Use interfaces, so that the actual underlying data structure can be actually
changed without impacting the client program
Null out references when they are no longer needed so that gc can collect
them when it is running.
Floating point increments are much slower than any integral increment.
It can help to copy slower-access vars to fast local vars if you are going to
operate on them repeatedly, as in a loop.
For some applications that access the date a lot, it can help to set the local
timezone to be GMT, so that no conversion has to take place.
http://marancollects.blogspot.com
1/10
your application so that subsequent steps can start working on the portion of
data that any prior process has finished, instead of having to wait until the
prior process is complete.
Define methods that accept reusable objects to be filled in with data, rather
than methods that return objects holding that data.
Use private and static methods and final classes to encourage inlining by the
compiler
Keep methods short and simple to make them automatic inlining candidates
Access to private member by the inner classes to the enclosing class goes by
a method call even if it is not intended to.
Perform the loop backwards (this actually performs slightly faster than
forward loops do). [Actually it is converting the test to compare against 0 that
makes the difference].
It can help to copy slower-access vars to fast local vars if you are going to
operate on them repeatedly, as in a loop.
http://marancollects.blogspot.com
2/10
For multidimensional arrays store a reference for the currently accessed row
in a variable.
Cache the size of the collection in a local variable to use in a loop instead of
repeatedly calling collection.size().
Optimizing Strings:
method,
because
internally
Use char arrays for all character processing in loops, rather than using String
or StringBuffer classes
Where the compiler cannot resolve concatenated strings at compile time, the
code should be converted to StringBuffer appends, and the StringBuffer
should be appropriately sized rather than using the default size.
The compiler concatenates strings where they are fully resolvable, so don t
move these concatenations to runtime with StringBuffer.
Iterator.hasNext()
and
repeatedly
when
called
Enumerator.hasMoreElements()
the
size
of
the
collection
need
is
not
known.
be
Use
http://marancollects.blogspot.com
3/10
LinkedList is faster than ArrayList for inserting elements to the front of the
array, but slower at indexed lookup
Removing elements from a Vector will necessitate copying within the Vector if
the element is removed from anywhere other than the end of the collection.
Presizing collections to the expected size is more efficient than using the
default size and letting the collection grow.
For multidimensional arrays store a reference for the currently accessed row
in a variable.
When adding multiple items to a collection, add them all in one call if
possible.
Optimizing threads:
Polling is only acceptable when waiting for outside events and should be
performed in a "side" thread. Use wait/notify instead.
Optimizing IO?
File information such as file length requires a system call and can be slow
Dont use it often. Similarly, System.currentTimeMillis() uses a native call to
http://marancollects.blogspot.com
4/10
get current time. Make sure your production code does not have this
statement.
Use the transient keyword to define fields to avoid having those fields
serialized. Examine serialized objects to determine which fields do not need to
be serialized for the application to work.
Increase server listen queues for high load or high latency servers.
Optimizing exceptions:
Always use the finally block to release the resources to prevent resource
leaks.
Choose
right
isolation
level
as
per
your
requirement.
Use PreparedStatement when you execute the same statement more than
once.
Use CallableStatement when you want result from multiple and complex
statements for a single request.
Close ResultSet, Statement and Connection whenever you finish your work
with them.
http://marancollects.blogspot.com
5/10
Fetch small amount of data iteratively rather than whole data at once when
retrieving large amount of data like searching database etc.
Optimizing servlets:
Use StringBuffer rather than using + operator when you concatenate multiple
strings
Use thread pool for your servlet engine and define the size as per application
requirement.
Use StringBuffer rather than using + operator when you concatenate multiple
strings
Initialize the 'out' object (implicit object) with proper size in the page
directive.
http://marancollects.blogspot.com
6/10
Give 'false' value to the session in the page directive to avoid session object
creation.
Use include directive instead of include action when you want to include the
child page content in the translation phase.
Remove 'session' objects explicitly in your program whenever you finish the
task
Use thread pool for your JSP engine and define the size of thread pool as per
application requirement.
Use Local interfaces that are available in EJB2.0 if you deploy both EJB Client
and EJB in the same EJB Server.
Wrap entity beans with session beans to reduce network calls and to promote
declarative transactions. Optionally, make entity beans as local beans where
appropriate.
Make coarse grained session and entity beans to reduce network calls.
http://marancollects.blogspot.com
7/10
Tune thread count for EJB Server to increase EJB Server capacity.
Choose normal java object over EJB if you don't want built-in services such as
RMI/IIOP, transactions, security, persistence, resource pooling, thread safe,
client state etc..
Tune the Stateless session beans pool size to avoid overhead of creation and
destruction of beans.
Tune Stateful session beans cache size to avoid overhead of activation and
passivation process.
Use 'transient' key word for unnecessary variables of Stateful session bean to
avoid serialization overhead.
Remove Stateful session beans explicitly from client using remove() method.
Tune the entity beans pool size to avoid overhead of creation and destruction
of beans.
Tune the entity beans cache size to avoid overhead of activation, passivation
and database calls.
http://marancollects.blogspot.com
8/10
Commit the data after the transaction completes to reduce database calls in
between transaction.
Use CMP rather than BMP to utilize built-in performance optimization facilities
of CMP.
Use direct JDBC rather than using entity beans when dealing with huge data
such as searching a large database.
Tune the Message driven beans pool size to promote concurrent processing of
messages.
http://marancollects.blogspot.com
9/10
Use 'transient' key word for variables of ObjectMessage which need not be
transferred.
http://marancollects.blogspot.com
10/10