[External] : Re: Dropped task -- feature or bug?
Ron Pressler
ron.pressler at oracle.com
Tue May 17 07:11:25 UTC 2022
On 16 May 2022, at 20:02, Brian S O'Neill <bronee at gmail.com<mailto:bronee at gmail.com>> wrote:
I wouldn't necessarily need full tracking behavior to debug the issue. When the virtual thread is blocked, I can find my task in a heap dump, referred to by a continuation object. Regardless, is the current behavior a feature, a bug, or is it just a strange anomaly that needs to be documented?
It is by design — virtual threads are lightweight objects; like HashMaps, we don’t maintain a registry of all instances — and this behaviour is described in JEP 425. If you create a thread that could become unreachable, it also *probably* means that nothing is awaiting its result and that nothing would notice if it had an uncaught exception, i.e. you’re doing something risky and specialised, so we don’t want to add a registration mechanism in such specialised uses. (I say “probably” because you could join a thread without holding a reference to it, but you’d be without any means of interrupting it).
Now, by “tracking” I meant that the thread is reachable from some object that is known to observability mechanisms so that it could appear in a thread-dump. In ordinary use, virtual threads will be created by newVirtualThreadPerTaskExecutor or by structured concurrency, so that something "keeps an eye on them” and cares when they finish or if they throw, so they need to be kept alive, anyway.
— Ron
More information about the loom-dev
mailing list