1. Carefully consider how collections will be accessed and choose the right type of
synchronization for them. However, the penalty for uncontended access to a
memory-protected collection (particularly one using CAS-based protections) is
minimal; sometimes it is better to be safe than sorry.
2. Sizing of collections can have a large impact on performance: either slowing
down the garbage collector if the collection is too large, or causing lots of copying
and resizing if it is too small.
The AggressiveOpts flag (by default, false ) affects the behavior of several basic Java SE
operations. The purpose of this flag is to introduce optimizations on a trial basis; over time,
the optimizations enabled by this flag can be expected to become the default setting for the
JVM. Many of those optimizations that were experimented with in Java 6 became the default
in Java 7u4. You should retest this flag with every release of the JDK to see if it is still posit-
ively affecting your application.
The major effect of enabling the AggressiveOpts flag is that it substitutes different imple-
mentations for several basic JDK classes: notably, the BigDecimal , BigInteger , and Mut-
ableBigDecimal classes from the java.math package; the DecimalFormat , DigitalList ,
and NumberFormat classes from the java.text package; and the HashMap , LinkedHashMap ,
and TreeMap classes from the java.util package.
These classes are functionally the same as the classes in the standard JDK that they replace,
but they have more efficient implementations. In Java 8, these alternate implementations
have been removed; either they have been incorporated into the base JDK classes, or the base
JDK classes have been improved in other ways.
The reason that these classes are enabled (in Java 7) only when the AggressiveOpts flag is
set is because their behavior can trigger subtle bugs in application code. For example, the ag-
gressive implementation of the HashMap class yields an iterator that returns the keys in a dif-
ferent order than the standard implementation. Applications should never depend on the or-