Java 25 Released: Virtual Threads Stable, String Templates Officially GA

Java 25 has been officially released, and several features are worth paying attention to.

Virtual Threads Officially GA

Virtual threads were in Preview in Java 21 and are now stable.

// Before: one request per platform thread, blocking when the thread pool is exhausted
ExecutorService exec = Executors.newFixedThreadPool(200);

// Now: one request per virtual thread, with virtually no limits
ExecutorService exec = Executors.newVirtualThreadPerTaskExecutor();

In real-world testing, with the same machine resource configuration, throughput improved by 3-5 times when using virtual threads. This is because virtual threads don't occupy OS threads—when blocked, they are automatically suspended, freeing up the underlying platform threads.

String Templates

Say goodbye to StringBuilder hell:

// Before
String sql = "SELECT * FROM users WHERE id = " + userId;

// Now
String sql = STR."SELECT * FROM users WHERE id = \{userId}";

Note: String templates include SQL injection protection by default, and different processors have different escaping rules.

Other Improvements

  • Pattern Matching further refined
  • Foreign Function & Memory API officially GA
  • ZGC generational mode enabled by default

Java's evolution pace in recent years has been remarkably fast, keeping up with the demands of the cloud-native era.


References:

About Zihao Zhang

Data Platform Engineer. Distributed systems, OLAP databases, AI Agent development.

Comments

Comments are closed.

Ask Me Anything
Hey! I'm Hank's digital avatar. How'd you find your way here?
⚠️ AI-powered · May be inaccurate · Powered by DeepSeek
Chat Logs