Virtual Threads are no longer Preview:
Virtual threads have been introduced as a part of Project looms which can be used as a preview feature in Java.
The key feature of this is virtual threads. These are designed to look to the programmer like “just threads.”
However virtual threads are managed by the Java runtime and are not thin, one-to-one wrappers over OS threads.
Instead, they are implemented in user space by the Java runtime. The major advantages that virtual threads are intended to bring include
Creating and blocking them is cheap.
Standard Java execution schedulers (threadpools) can be used.
No OS-level data structures are needed for the stack.
The removal of the involvement of the operating system in the lifecycle of a virtual thread is what removes the scalability bottleneck.
What other means:
Massive scalability for blocking I/O workloads
Cleaner code vs reactive stacks
Perfect fit for: Spring Boot and REST APIs /JDBC / JPA
Structured Concurrency In Action
Structured concurrency matures into a safe, predictable model for parallel tasks.
Scoped Values — Safer Context Propagation
In Java, scoped variables refer to variables whose lifetime and visibility are limited to a specific block or context.
This is a general concept, but in modern Java (especially with Project Loomand Java 21+), the term “scoped variables” is gaining special meaning through a new feature called: “ScopedValue"
ScopedValue is a new type-safe alternative to ThreadLocal, designed for use with virtual threads.
What is Scoped Value
ScopedValue<T> allows you to define a value that's:
Immutable
Visible only within a specific dynamic scope
Thread-safe, especially in virtual threads
It’s useful for passing contextual information (like request ID, user info, etc.) down a call chain without using method parameters — and without the pitfalls of ThreadLocal.
For Example:
static final ScopedValue<String> USERNAME = ScopedValue.newInstance();
public static void main(String[] args) {
ScopedValue.where(USERNAME, "vikas").run(() -> {
greet(); // prints "Hello, vikas"
});
}
static void greet() {
System.out.println("Hello, " + USERNAME.get());
}Here:
The value
"vikas"is only available within the scope of therun()call.USERNAME.get()will throwIllegalStateExceptionif accessed outside the scope
Pattern Matching for Switch Statements:
Key Aspects of Pattern Matching for Switch
Switch case can match the pattern now instead of just matching the constant value.
Reduce boilerplate code like if-else-if statements.
More expressive and readable code.
Eliminate type casting using instanceOf.
Lets look at the below example:
if (object instanceof String) {
String s = (String) obj;
// Handle string case
} else if (obj instanceof Integer) {
Integer i = (Integer) obj;
// Handle integer case
} // and so on...Now lets use the Pattern Matching for the Switch Statement.
switch (object) {
case String s -> // Handle string case
case Integer i -> // Handle integer case
// and so on...
default -> // Handle the default case
}Lets Look at the record.
public record Point(int x, int y) {}public class SwitchPatternMatchingExample {
public static void main(String[] args) {
Object obj = // ... some object
String result = switch (obj) {
case String s -> "String of length " + s.length();
case Integer i -> "Integer with value " + i;
case Point p && p.x == p.y -> "Same X,Y Cooridinates "
case Point p-> "Point with X Axis " + r.x + " and Y Axis " + p.y;
default -> "Unknown object";
};
System.out.println(result);
}
}Lets look at an ENUM example:
public enum TrafficLightsColors {
RED, YELLOW, GREEN;
}Lets Look at the Switch Statement:
public class TrafficLightColorExample {
public static void main(String[] args) {
TrafficLightsColors light = // some value from TrafficLight enum
String action = switch (light) {
case RED -> "Stop";
case YELLOW -> "Prepare to stop";
case GREEN -> "Go";
};
System.out.println("The light is " + light + ": " + action);
}
}There are other significant Java 25 features and you can find the detailed list in the reference below. Please share and clap if you liked my content.
Please subscribe for more stories.
