Movatterモバイル変換


[0]ホーム

URL:


Skip toContent

Concurrency Utilities Enhancements in Java SE 8

New classes and interfaces in java.util.concurrent

Thejava.util.concurrent package contains two new interfaces and four new classes:

New methods in java.util.concurrent.ConcurrentHashMap

TheCollections Framework has undergone a major revision in Java 8 to add aggregate operations based on the newly addedstreams facility andlambda expressions. As a result, theConcurrentHashMap class introduces over 30 new methods in this release. These include variousforEach methods (forEach,forEachKey,forEachValue, andforEachEntry), search methods (search,searchKeys,searchValues, andsearchEntries) and a large number of reduction methods (reduce,reduceToDouble,reduceToLong etc.)

Other miscellaneous methods (mappingCount andnewKeySet) have been added as well. As a result of the JDK 8 changes,ConcurrentHashMaps (and classes built from them) are now more useful as caches. These changes include methods to compute values for keys when they are not present, plus improved support for scanning (and possibly evicting) entries, as well as better support for maps with large numbers of elements.

For complete details, see thejava.util.concurrent.ConcurrentHashMap API specification.

New classes in java.util.concurrent.atomic

Maintaining a single count, sum, etc. that is updated by possibly many threadsis a common scalability problem. This release introduces scalable updatable variablesupport through a small set of new classes (DoubleAccumulator,DoubleAdder,LongAccumulator,LongAdder), which internally employ contention-reduction techniques that provide huge throughput improvements as compared toAtomic variables. This is made possible by relaxing atomicity guarantees in a way that is acceptable in most applications.

New methods in java.util.concurrent.ForkJoinPool

A staticcommonPool() method is now available and appropriate for most applications. The common pool is used by anyForkJoinTask that is not explicitly submitted to a specified pool. Using the common pool normally reduces resource usage (its threads are slowly reclaimed during periods of non-use, and reinstated upon subsequent use). Two new methods (getCommonPoolParallelism() andcommonPool()) have been added, which return the targeted parallelism level of the common pool, or the common pool instance, respectively.

New class java.util.concurrent.locks.StampedLock

A newStampedLock class adds a capability-based lock with three modes for controlling read/write access (writing, reading, and optimistic reading). This class also supports methods that conditionally provide conversions across the three modes.

For complete details, see thejava.util.concurrent.StampedLock API documentation.


Copyright © 1993, 2025, Oracleand/or its affiliates. All rights reserved.
Contact Us

[8]ページ先頭

©2009-2025 Movatter.jp