Menu

Java Virtual Threads Aren't Free: 6 Hidden Costs to Check Before Production
📰

Java Virtual Threads Aren't Free: 6 Hidden Costs to Check Before Production

DEV Community: java·Neetu·9 days ago
#JxqIGXuf
#devtojava#devto#dev#virtual#thread
Reading 0:00
15s threshold

Java virtual threads make it cheap to run a huge number of concurrent tasks, but they don't make your system's limits go away. Memory, database connections, CPU cores, locks and observability all still cost something. Virtual threads were previewed in Java 19 (JEP 425) and became a standard feature in Java 21 (JEP 444). Here are six costs worth checking before you switch a production service over.

What do Java virtual threads actually change?

A virtual thread is a lightweight thread managed by the JVM rather than the operating system. When it blocks on I/O, the JVM unmounts it from its carrier (an ordinary platform thread), and that carrier picks up other work. That is why simple thread-per-request code can scale again without callbacks or reactive chains.

What doesn't change is everything the thread talks to.

1. Memory still adds up

Virtual threads are cheap, not weightless. Each one keeps its stack on the Java heap, and that stack grows with the depth of the call chain.…

Continue reading — create a free account

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