Details
-
Bug
-
Resolution: Fixed
-
P3
-
19, 20
-
b10
-
Verified
Backports
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-8293731 | 19.0.2 | Robert Mckenna | P3 | Resolved | Fixed | b01 |
JDK-8293689 | 19.0.1 | Robert Mckenna | P3 | Resolved | Fixed | b10 |
Description
TerminatingThreadLocal is a JDK internal variant of ThreadLocal wihth a cleanup action to be called when a thread with bound value for a particular TerminatingThreadLocal instance is terminating. It is used internaly in JDK for prompt cleanup of thread-local caches of native ByteBuffer(s) and NativeBuffer(s). TerminatingThreadLocal is only ever used in the context of carrier threads. If a virtual thread is accessing a value, it is actually its currently bound carrier thread that is selected to hold the value. But if only virtual threads are creating the value(s) such TerminatingThreadLocal(s) are never registered and cleanup action is not called when the carrier thread exits:
```
public static void register(TerminatingThreadLocal<?> tl) {
if (!Thread.currentThread().isVirtual())
REGISTRY.get().add(tl);
}
```
You may say that carrier threads live forever, but that's not true. When the "virtual thread scheduler" (ForkJoinPool) is compensating for a pinned carrier thread that blocks, new carrier thread is created. After keep-alive period (30 seconds currently) of inactivity, such excessive carrier threads are terminated.
```
public static void register(TerminatingThreadLocal<?> tl) {
if (!Thread.currentThread().isVirtual())
REGISTRY.get().add(tl);
}
```
You may say that carrier threads live forever, but that's not true. When the "virtual thread scheduler" (ForkJoinPool) is compensating for a pinned carrier thread that blocks, new carrier thread is created. After keep-alive period (30 seconds currently) of inactivity, such excessive carrier threads are terminated.
Attachments
Issue Links
- backported by
-
JDK-8293689 TerminatingThreadLocal(s) not registered from virtual thread(s)
-
- Resolved
-
-
JDK-8293731 TerminatingThreadLocal(s) not registered from virtual thread(s)
-
- Resolved
-
- relates to
-
JDK-8292051 jdk/internal/misc/TerminatingThreadLocal/TestTerminatingThreadLocal.java failed "AssertionError: Expected terminated values: [666] but got: []"
-
- Closed
-
- links to
-
Commit openjdk/jdk19u/5d304f52
-
Commit openjdk/jdk/861cc671
-
Review openjdk/jdk19u/23
-
Review openjdk/jdk/9743
(2 links to)