Java concurrency changes from Java8 to Java9


1. New classes and interfaces in java.util.concurrent

Two new interfaces and 4 new classes have been added:

Java9 Interface for concurrency

  • Interface CompletableFuture.AsynchronousCompletionTask
  • Interface CompletionStage

Java9 Classes for concurrency

  • Class CompletableFuture
  • Class ConcurrentHashMap.KeySetView
  • Class CountedCompleter
  • Class CompletionException

2. New method of java.util.concurrent.ConcurrentHashMap

The collection framework was revised in Java 8 and many aggregation methods were added based on stream and lambda expressions. Therefore, ConcurrentHashMap also introduced more than 30 new methods, including various foreach methods (forEach, forEachKey, forEachValue, and forEachEntry), search methods (search, searchKeys, searchValues, and searchEntries) and reduction methods (reduce, reduceToDouble, reduceToLong, etc.).

Some other methods have also been added, such as mappingCount and newKeySet. And the current version of ConcurrentHashMap is more suitable for cache, because it adds a check method when the key value does not exist.

3. Java9 New classes in java.util.concurrent.atomic

In order to calculate count and sum concurrently, the DoubleAccumulator, DoubleAdder, LongAccumulator, LongAdder classes are newly introduced, which provide higher throughput than Atomic.

4. New method for java.util.concurrent.ForkJoinPool

The static commonPool () is newly added to provide a common pool for ForkJoinTask.

The two methods getCommonPoolParallelism () and commonPool () provide different configurations.

5. New class in Java9 java.util.concurrent.locks.StampedLock

The new class StampedLock provides three modes (write, read, optimistic read) to improve performance.

6. Changes to Concurrent package in Java9

Mainly JEP 266: More Concurrency Updates, including publish-subscribe, CompletableFuture interface enhancement, etc.

Support Reactive Streams publish-subscribe framework, four interfaces Processor, Publisher, Subscriber, Subscription, container class java.util.concurrent.Flow, java.util.concurrent.SubmissionPublisher
CompletableFuture class enhancement, support delays, timeout, subclassing and other methods
Tuning and modifying javadoc

%d bloggers like this: