Java virtual threads

Content:

Original link: The thread-per-request ceiling is real / Tomasz Markiewicz / LinkedIn.

Async programming is definitely in fashion these years because it can improve performance significantly.

The is a small problem: it is costly to rewrite a code base from sync to async. There is a big problem: async code tend to hard to read and hard to debug cause maintenance cost to go up and stability to go down.

Java 19/21 intrdouced a concept of virtual threads, which provides some of the same benefits as async with no or minimal code changes.

Someone did a benchmark:

base : 177 req/sec
total rewrite to async : 2279 req/sec
config change to enable virtual threads : 320 req/sec
the latter is a zero cost increase in performance. And I am willing to predict that as the JDBC driver and ORM authors start writing for virtual threads (today it is probably only the low level socket code that do so), then virtual threads will narrow the gap to custom async code.

Comments: