Project Loom VirtualThreads hang

Ron Pressler ron.pressler at oracle.com
Tue Jan 3 22:16:41 UTC 2023



On 3 Jan 2023, at 19:24, thurston N <thurston.nomagicsoftware at gmail.com<mailto:thurston.nomagicsoftware at gmail.com>> wrote:

Hello Ron,

Quoting:

"Virtual threads replace short individual *tasks* in your application, not platform threads."


 Why short?


Take a TCP server's accept loop.  I would have thought that's a natural target for execution in a virtual thread.


And it's more or less intended to run forever.

A small number of virtual threads may run for a long time, but the vast majority would be short lived. They would naturally form a hierarchy: you’d have one or a couple of threads accepting connections that live forever, several thousand request-handling threads that live as long as a single request, and then tens of thousands or more each servicing a single outgoing service request in a fanout, and those would be even shorter-lived.


"They are best thought of as a business logic entity representing a task rather than an “execution resource.”"


That's a pretty good definition of an "actor" (as in actors-model).  But there's no (even implicit) restriction on the duration of

an actor's lifetime.

Is it your intent to proscribe virtual threads as a possible implementation for actor-model type designs?

Threads are sequential task that is done concurrently with others. What protocols are used to communicate among threads (and the actor model is a communication protocol) is up to the programmer. An actor model is a bit too high-level for the JDK, but libraries may certainly offer actors based on virtual threads, just as others may build other high level constructs.



I'm thinking of simulations, e.g. modelling a migrating herd, bees at a honeycomb, a very busy traffic intersection, et al.

It seems natural (even elegant) to represent each of those entities (deer, bee, car) as a virtual thread, and executing them as a

platform thread isn't an option (because of their sheer number, the essence of the problem that virtual threads is the solution for)

And I'm sure there are innumerable other circumstances that could benefit from LWP (as Erlang terms them)

IMO, it's awfully reductive to restrict practical uses of virtual threads to writing sequential single request/response scenarios



My intent is not to restrict so much as to focus. Simulations are absolutely a great use-case for lightweight threads, but there are implementation choices that may need to balance some desirable properties with others and could result in virtual threads being a better fit for some use-cases than others. Because there are significantly more Java servers than Java simulations, and because servers are normally more complex (in terms of failure modes and architectural graph) and their developers are more mainstream and could benefit from more help, *if* there’s some prioritisation to be made, the server use-case is the one we prioritise over others by addressing it *first*. More people are interested in that use-case, that’s where virtual threads can contribute the most value, and that’s why it’s our *initial* focus.

— Ron
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/loom-dev/attachments/20230103/17664ed7/attachment-0001.htm>


More information about the loom-dev mailing list