Get ahead
VMware offers training and certification to turbo-charge your progress.
Learn moreProject Loom and virtual threads (JEP 444) changed the calculus on blocking. Java applications no longer need to be async and non-blocking to scale. Simply block, and the JDK handles platform thread sharing transparently. Application code doesn't have to change. It's a win-win.
In the Spring ecosystem, Spring MVC and WebFlux are separate stacks, blocking and non-blocking. Spring MVC remained mainstream, and those applications can benefit from virtual threads without a rewrite.
The current Spring Framework generation has a JDK 17 baseline, but recommends JDK 25 as the latest LTS release.
This allows applications to take full advantage of Loom today, crucially with JEP 491 on Java 24+ resolving thread pinning when using synchronized.
Modern applications have many cases for concurrency. Structured Concurrency (JEP 543) in Java 28 addresses that need. It removes async complexity from source code and from stacktraces at runtime.
There is one key remaining piece for applications on a Loom-friendly stack.
SSE, LLM tokens, and MCP responses are streams. Data streaming is central to AI applications. Spring AI and the MCP Java SDK need the Loom equivalent of Reactive Streams to transition from a reactive to a VT-friendly stack.
Historically in Java, whether it's WebSocket or messaging, data streaming has been commonly modeled as a push-style, callback handler. That comes with challenges. In a simple implementation with a direct invocation, blocking in the handler stalls the producer. A more advanced implementation with a dedicated thread is more complex and potentially inefficient.
What is a Loom-friendly approach?
For imperative code we prefer a simple, pull-style consumer loop. Iteration over items from a network with a lifecycle. The consumer loop runs on one thread, and is neutral to whether the producer is passive (direct hand-off) or active (independent thread with a hand-off queue).
There is currently no simple, standard way to do this in Java. The Structured Concurrency JEP mentions "channels" as a possible future goal. We need an interim solution with a baseline suitable for applications today.
stream-source is a small library that provides building blocks for Loom-friendly data streaming in Java. It is a core facility with wide applicability for the Java ecosystem.
Built by the Spring team, but not dependent on Spring. A low-level project like Micrometer and Reactor. It has only two dependencies, JSpecify and SLF4J.
The baseline is Java 17. Virtual threads are used by default on Java 21+.
stream-source comes with Reactive Streams adapters for bridging to/from existing libraries (e.g. JDK HttpClient) and codebases.
Source is the most central contract. For consumers, it defines the receiving loop:
try (Source<String> source = ...) {
while (source.receiveNext()) {
String item = source.next();
// process item
}
}
Use intry-with-resources ensures the release of underlying resources.
receiveNext blocks for the next item, next makes it available.
The loop ends when receiveNext returns false or throws an exception.
For producers, Source is a contract to implement, typically extending AbstractSource.
A Source can be decorated to have generic capabilities added.
Receiving directly from a Source works, but couples producer and consumer in sequential processing.
What if the consumer needs to perform I/O after receiving an item?
The producer would have to wait until the consumer calls receiveNext() again.
Exchange is a contract that enables producer and consumer to operate on different threads.
It has a Sink side to push into and a Source side to pull from.
The main implementation uses a BlockingQueue for the hand-off of items, which applies backpressure when producer and consumer rates diverge.
SourceTask helps to make use of this.
It starts a producer task in background thread pushing into an Exchange while the consumer receives from it:
Source<String> sseSource = ... ;
SourceTask<String> sourceTask = SourceTask.fromSource(sseSource);
try (Source<String> source = sourceTask.start()) {
while (source.receiveNext()) {
String item = source.next();
// process item
}
}
A more in-depth walkthrough is available. See Next Steps below.
Version 0.8.0 is available today. A milestone phase will begin early next year with a 1.0 GA in May 2027.
Spring AI 3.0 and the MCP Java SDK plan to build on stream-source for their streaming API needs with GA versions in May 2027. Stay tuned for a follow-up announcement from Spring AI this Thursday, December 3.
Spring Framework 7.2 will feature stream-source support in November 2027.
Check the experimental SSE support for RestClient in stream-source-spring-extensions.
When the JDK has a proposal for "channels", we will adapt accordingly.
For more, go to the stream-source repository.
Review the DESIGN and FAQ docs.
Experiment with the SSE RestClient support in stream-source-spring-extensions.
Stay tuned for a follow-up announcement from Spring AI this Thursday with further examples and concrete use cases. Follow java-sdk#778 for similar developments in the MCP JDK.
Please, consider how this library applies to your use cases. We look forward to hearing from you in the project issue trackers!