Menu

1 / 6

Java Virtual Threads vs Kotlin Coroutines: Suspension Models and the Shifting Bottleneck

DEV Community: java·Yongho Hwang·17 days ago
#YASgj6AA
#devtojava#devto#dev#thread#virtual
Reading 0:00
15s threshold

The usage and internals of Java virtual threads and Kotlin coroutines are already widely covered.

Rather than explaining each technology separately, this post compares how their different ways of implementing suspension change how code is written and operated.

It is written for JVM server developers who have adopted or are evaluating virtual threads, and it focuses on where the costs that virtual threads keep out of the code show up at runtime.

In a thread-per-request server, the number of threads is the concurrency limit .

With a pool of 200 threads, the 201st request waits until one of the 200 finishes.

Yet many of those 200 threads are not computing anything. They are simply blocked, waiting for a response from a database or an external API.

An expensive resource stays tied up while doing nothing, and that is not a small problem.

The fix is simple in principle: release the OS thread while waiting .

Doing this by hand, however, changes the structure of the code.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.