JDK21 9 月 19 日 来咯!

2023-09-19 09:39:56 +08:00
 forschers

Visual Threads (虚拟线程)来了,终于可以把 8 换了。

7252 次点击
所在节点    Java
66 条回复
Aresxue
2023-09-20 10:11:29 +08:00
@mmdsun 真这么简单早升级完了,光 JPMS 和反射的限制就够喝一壶的,更别提原有的 java agent 可能都要失效了,我手上的项目 100 多个应用,2000 多个 pod ,要真到 21 没个两年下不来。
zhouhu
2023-09-20 10:34:30 +08:00
@voidmnwzp
你说的是这个吧
There are two scenarios in which a virtual thread cannot be unmounted during blocking operations because it is pinned to its carrier:

When it executes code inside a synchronized block or method, or
When it executes a native method or a foreign function.

官方解释:
The scheduler does not compensate for pinning by expanding its parallelism. Instead, avoid frequent and long-lived pinning by revising synchronized blocks or methods that run frequently and guard potentially long I/O operations to use java.util.concurrent.locks.ReentrantLock instead. There is no need to replace synchronized blocks and methods that are used infrequently (e.g., only performed at startup) or that guard in-memory operations. As always, strive to keep locking policies simple and clear.

后续优化:
In a future release we may be able to remove the first limitation above, namely pinning inside synchronized. The second limitation is required for proper interaction with native code.
arloor
2023-09-20 11:57:19 +08:00
@zhouhu pin 是什么意思
zhouhu
2023-09-20 12:24:03 +08:00
@arloor
some blocking operations in the JDK do not unmount the virtual thread, and thus block both its carrier and the underlying OS thread.

If a virtual thread performs a blocking operation such as I/O or BlockingQueue.take() while it is pinned, then its carrier and the underlying OS thread are blocked for the duration of the operation. Frequent pinning for long durations can harm the scalability of an application by capturing carriers.
Subfire
2023-09-20 16:23:12 +08:00
为啥换成 JDK21 后,
import java.util.concurrent.TimeUnit;
这个都报错
javaZhenJuan
2023-09-21 17:14:36 +08:00
@Subfire 我的也报错

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/975067

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX