Tuning Techniques

Java Enterprise performance-tuning techniques include J2SE tuning techniques, as well as a variety of others. Here is a summary of the J2SE best practice techniques:

  • Improve CPU limitations with faster code, better algorithms, and fewer short-lived objects.

  • Improve memory limitations by using fewer objects or smaller long-lived objects.

  • Improve I/O limitations by reducing the number of I/O operations with targeted redesigns, or by speeding up I/O by reducing the amount of data requiring I/O, or perhaps by multithreading the I/O. Buffer I/O where possible (usually almost everywhere).

  • Switch to an optimizing compiler.

  • Use a JIT-enabled JVM.

  • Test other JVMs to find a faster one.

  • Turn off any JVM options that slow down the application (e.g., -Xrunhprof and -verbose ).

  • Tune the heap.

  • If a bottleneck consists of a slow method, make it faster.

  • If a bottleneck consists of many calls to a fast method, reduce the number of times that method is called.

  • Tune object-creation and garbage-collection bottlenecks by reusing objects and reducing the number of objects used.

  • Target loops. Minimize the time executed in the loop by moving any code you can outside the loop, avoiding repeated operations and inlining method calls.

  • Target strings. Only internationalized text needs to use String objects. All other string use can probably be optimized with your own character handling.

  • Try to use primitive datatypes directly. Avoid wrapping them.

  • Use or build the fastest collection possible. Traverse ...

Get Java Enterprise Best Practices now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.