News for hackers. Stuff that matters.
Re:Show HN: I finished v5 of a JVM framework I've spent spen... by heurisko on Monday October 03, 2022 @01:11PM (#33070498)
Given Project Loom hasn't been available, how does it utilise Virtual Threads already?
Re:Show HN: I finished v5 of a JVM framework I've spent spen... by tipsee on Monday October 03, 2022 @01:29PM (#33070786)
If you run this on JDK19 with *--enable-preview*, Javalin will use Virtual Threads for the Server ThreadPool (as well as all other ThreadPools it has).
Re:Show HN: I finished v5 of a JVM framework I've spent spen... by daveidol on Monday October 03, 2022 @01:48PM (#33071075)
How does it compare to coroutines in Kotlin?
Re:Show HN: I finished v5 of a JVM framework I've spent spen... by tipsee on Monday October 03, 2022 @01:56PM (#33071195)
I mean, it sort of doesn't? Coroutines is a whole concept, Virtual Threads can in most cases just replace java.lang.Threads, which is how it's implemented in Javalin. We just swap out the OS Threads for Virtual Threads.
Re:Show HN: I finished v5 of a JVM framework I've spent spen... by stefs on Monday October 03, 2022 @01:58PM (#33071229)
i'd be interested in this too. my guess: virtual threads are slightly more memory efficient and slightly faster, but same ballpark.
Re:Show HN: I finished v5 of a JVM framework I've spent spen... by stefs on Thursday October 06, 2022 @09:07AM (#33107737)
now that i think about it i'm pretty sure my guess is completely wrong. memory usage (and thus concurrent-inactives) might be similar, but i expect the virtual threads to be much more efficient.
Re:Show HN: I finished v5 of a JVM framework I've spent spen... by stefs on Friday October 07, 2022 @05:57AM (#33119289)
except if you use the appropriate non-blocking methods! with blocking io, kotlin coroutines are just running in a thread pool.
Re:Show HN: I finished v5 of a JVM framework I've spent spen... by oweiler on Monday October 03, 2022 @01:15PM (#33070558)
Project Loom is in preview, and far from available. As far as I can see, Javalin doesn't make use of virtual threads yet.
Re:Show HN: I finished v5 of a JVM framework I've spent spen... by tipsee on Monday October 03, 2022 @01:30PM (#33070805)
It does :)

We use reflection to build the Virtual Thread Factory if the user has Loom enabled in their enviroment: https://github.com/javalin/javalin/blob/master/javalin/src/m...

Re:Show HN: I finished v5 of a JVM framework I've spent spen... by pron on Monday October 03, 2022 @04:57PM (#33073606)
Virtual threads are already available in the current version of the JDK (19) as a Preview feature. Because it's not a preview language feature but a preview API, libraries can use it without compiling with --enable-preview, either with reflection or by having the application supply a virtual thread ThreadFactory, which means they can make use of virtual threads if the application turns preview features on.

Preview language features are different as they require compiling with --enable-preview, which creates a "poisoned" class file that cannot be loaded at all without preview enabled, so preview language features are not recommended for use by libraries, but preview APIs are fine (see JEP 12: Preview Features https://openjdk.org/jeps/12).