Skip to content
欢迎扫码关注公众号

JEP 155: Concurrency Updates | 并发更新

摘要

可扩展的可更新变量,面向缓存的 ConcurrentHashMap API 增强,ForkJoinPool 改进,以及额外的 LockFuture 类。

动机

应用程序中并发性和并行性使用的不断发展要求库支持的不断演进。这里描述的所有工作都是由 java.util.concurrent 包的用户经验和建议所推动的。

描述

  1. 可扩展的可更新变量。维护一个由可能多个线程更新的单一计数、总和等是一个常见的可扩展性问题。一组新的类(DoubleAccumulatorDoubleAdderLongAccumulatorLongAdder)内部采用减少争用的技术,与 Atomic 变量相比,提供了巨大的吞吐量改进。这是通过以大多数应用程序可接受的方式放宽原子性保证来实现的。

  2. 增加了使 ConcurrentHashMaps 及其构建类作为缓存更加有用的功能(以及可能增加的 API)。这些功能包括在键不存在时计算其值的方法,以及改进了对扫描和可能逐出条目的支持,以及对包含大量元素的映射的更好支持。

  3. ForkJoinPool 添加了功能和改进了性能,使其能够在用户希望使用的越来越广泛的应用程序中更有效地使用。新功能包括支持基于完成的设计,这通常最适合于受 IO 限制的使用场景等。

可能的进一步添加包括额外的 LockFuture 类,以及重新考虑相关支持,以更好地构建 STM(软件事务内存)框架。但是,STM 支持本身不是 JDK 8 的目标。

这些组件的初步版本(以及其他一些小的更新)已经在 OpenJDK 之外推出,并将继续推出,以便在集成到 JDK 8 之前征求早期反馈和经验报告(主要由专家用户提供)。可以通过 http://gee.cs.oswego.edu/dl/concurrency-interest/index.html 上的链接找到源代码和邮件列表讨论。

测试

我们(JSR 166 的持续成员)为所有组件提供功能和性能测试。

风险和假设

我们假设 Oracle 工程师将继续协助将其集成到 JDK 8 中。

依赖

一些功能依赖于 lambda 语法和 JDK 中常见函数类型的声明,因此我们可能会推迟集成,直到我们对其最终形式更有信心。

Page Layout Max Width

Adjust the exact value of the page width of VitePress layout to adapt to different reading needs and screens.

Adjust the maximum width of the page layout
A ranged slider for user to choose and customize their desired width of the maximum width of the page layout can go.

Content Layout Max Width

Adjust the exact value of the document content width of VitePress layout to adapt to different reading needs and screens.

Adjust the maximum width of the content layout
A ranged slider for user to choose and customize their desired width of the maximum width of the content layout can go.