r/java • • Apr 06 '22

JEP 425: Virtual Threads (Preview)

https://openjdk.java.net/jeps/425
175 Upvotes

50 comments sorted by

View all comments

11

u/python_geek Apr 06 '22 edited Apr 06 '22

How does Kotlins coroutines fit in here for I/O bound work especially? IIRC, Kotlin has some compile time tricks to create a state machine.

The JEP mentions:

goroutines in Go and processes in Erlang

but nothing about Kotlin's coroutines.

Edit: actually, Kotlin is mentioned at the end:

Most languages that have adopted syntactic coroutines have done so due to an inability to implement user-mode threads (e.g., Kotlin), legacy semantic guarantees (e.g., the inherently single-threaded JavaScript), or language-specific technical constraints (e.g., C++). These limitations do not apply to Java.

14

u/koreth Apr 06 '22

At the risk of committing a faux pas by talking Kotlin in the Java subreddit: My understanding is that the two will play well together: it'll be easy to run coroutines on virtual-thread-based executors.

Obviously with virtual threads, coroutines will become unnecessary in some places where they're currently used as a way to run code on multiple threads. But as a language feature, coroutines are more than just a threading abstraction: they're used for dynamic generation of sequences and other things. Those use cases will still be just as valid in a Loom-based world.

9

u/buyIdris666 Apr 06 '22

Meh. Like async, coroutines will be a rarely used niche feature once Loom lands. Virtual threads appear to give 95% of the performance benefit while letting you write "normal" code. Very rare you need that extra 5%

0

u/[deleted] Apr 06 '22

[deleted]

5

u/rbygrave Apr 06 '22

Not answering your question but ... in terms of park/unpark Loom operates at a lower level. I can't help but think that longer term that would provide Loom a performance advantage.

Is anyone out there doing a comparison or intending to do one?

For myself, I've only tested loom performance against async using JDK HttpClient, Loom came slightly out on top there but that was a while ago - need to redo that test.

2

u/[deleted] Apr 07 '22

Looks like the Javalin creator did a comparison of QueuedThreadPool (with platform threads) vs. Loom threads vs. Loom threads with async.

https://github.com/tipsy/loomylin

This was done with an older early release Loom build.

1

u/[deleted] Apr 07 '22

Is /u/tipsy a thing? If so, maybe we can summon him and get his thoughts.