Documentation Contents

# Collections Framework Enhancements in Java SE 7

## New Interface, TransferQueue

The interface `TransferQueue` has been added. It is a refinement of the `BlockingQueue` interface in which producers can wait for consumers to receive elements. One implementation of the new interface is also included in this release, `LinkedTransferQueue`.

## Improved Hash Function

Java SE 7u6 introduces an improved, alternative hash function for the following map and map-derived collection implementations:

- `HashMap`
- `Hashtable`
- `HashSet`
- `LinkedHashMap`
- `LinkedHashSet`
- `WeakHashMap`
- `ConcurrentHashMap`

The alternative hash function improves the performance of these map implementations when a large number of key hash collisions are encountered.

For Java SE 7u6, this alternative hash function is implemented as follows:

- The alternative hash function is only applied to keys of type `String`.

- The alternative hash function is only applied to maps with a capacity larger than a specified threshold size. By default, the threshold is `-1`. This value disables the alternative hash function. To enable the alternative hash function (which is only applied to keys of type `String`), set the `jdk.map.althashing.threshold` system property to a different value. The recommended value is `512`. Setting this system property to `512` causes all maps with a capacity larger than 512 entries to use the alternative hash function. You can set this system property to `0`, which causes all maps to use the alternative hash function.

  The following describes the `jdk.map.althashing.threshold` system property in more detail:

  - Value type: Integer
  - Value default: `-1`
  - Value range: From -1 to 2147483647, inclusive
  - Description: Threshold capacity at which maps use the alternative hash function for keys of type `String`. The value `-1` is a synonym for `2147483647` (which is easier to remember). All other values correspond to threshold capacity.

  For example, the following command runs the Java application `MyApplication` and sets the `jdk.map.althashing.threshold` system property to `512`:

      java -Djdk.map.althashing.threshold=512 MyApplication

- If the alternative hash function is being used, then the iteration order of keys, values, and entities vary for each instance of `HashMap`, `Hashtable`, `HashSet`, and `ConcurrentHashMap`. This change in iteration order may cause compatibility issues with some programs. This is the reason that the alternative hash function is disabled by default. Hashing improvements will be investigated in future releases. In the meantime, the system property `jdk.map.althashing.threshold` is experimental. It is strongly recommended that you test your applications with the alternative hashing function enabled (by setting `jdk.map.althashing.threshold` to 0) to determine if your applications are affected by iteration order. If there is an impact, you should fix your applications as soon as possible because there is no guarantee of iteration order.

Copyright © 1993, 2014, Oracle and/or its affiliates. All rights reserved.
Contact Us