UTC 时间 2023 年 9 月 19 日,期盼已久的 Java 21 终于发布正式版! 本文一起来看看其中最受 Java 开发者关注的一项新特性:Loom 项目的两个新特性之一的 ”虚拟线程(Virtual Thread)“(另外一个新特性是 ”结构化并发(Structured Concurrency)“,当前是预览状态),它被称之为 Java 版的 ”协程“,它到底是...
[JDK 19] JEP 428: Structured Concurrency (Incubator) [JDK 20] JEP 437: Structured Concurrency (2nd Incubator) Value: Simplifies concurrent programming by introducing an API for structured concurrency. which streamlines error handling and cancellation, improves reliability, and enhances observability. ...
Java 21 的虚拟线程:高性能并发应用的福音 尽管Scoped Values (JEP 446) 和Structured Concurrency (JEP 453) 仍然是Java 21中的预览功能,但Virtual Threads已经成为一个成熟的、适用于生产环境的功能。 Java 21 最重要的特性之一就是虚拟线程 (JEP 444)。这些轻量级的线程降低了编写、维护和观察高吞吐量并行应用所...
Structured concurrency Task scheduling framework 即线程池,常见、易用。 Fork/join framework 即ForkJoinPool,不过目前还没有在项目中实际使用过。 Concurrent collections 线程安全的容器,比如BlockingQueue/BlockingDeque。 Atomic variables 原子变量,在java.util.concurrent.atomic下的类,比如AtomicInteger。 Synchronizers...
Structured concurrency was incubated in Java 19 and Java 20. Structured concurrency as previewed in JEP 453 for Java 21 simplifies the parallel execution of tasks by introducing a structured concurrency API. This approach treats batches of interrelated tasks, executed in separate threads, as a cohesi...
Structured Concurrency(结构化并发):通过引入 API 简化并发编程,将在不同线程中运行的相关任务组视为...
除了2.1.1 与 2.1.2 介绍的创建并运行虚拟线程的方法,Java21还引入了一个预览特性JEP 453: Structured Concurrency (Preview)来提供一种叫做结构化并发的API来提供更好的虚拟线程并发编程。这个新特性将来后续章节介绍。 2.1.3 虚拟线程 vs 平台线程 现在来看一个简单的并发连接并查询数据库单表的例子,通过这里我们...
(String Templates、Record Patterns、Pattern Matching for Switch、Unnamed Patterns and Variables 以及 Unnamed Classes and Instance Main Methods);Project Panama (Foreign Function & Memory API 和 Vector API) 的增強功能;與 Project Loom 相關的功能 (Virtual Threads、Scoped Values 和 Structured Concurrency);...
有关这些变更的更多细节,包括代码示例和对该功能背后动机的全面讨论,请参阅OpenJDK的网站。这个新的 API 是使并发编程更容易、更可靠和更具可观测性的重要一步。预计它对构建可维护的、可靠的和可观测的服务器应用尤为有利。 原文链接:https://www.infoq.com/news/2023/06/structured-concurrency-jdk......
21. Structured concurrency leverages this feature to write asynchronous code in a very easy way. It is built on an imperative mono-thread programming model built on top of virtual threads. These elements have been updated in Java 20. Java 20 also has a third preview feature delivered by the...