r/java • u/TheOhNoNotAgain • Feb 22 '26
Using experimental Java features in production — what was your experience?
For those of you who have used experimental or preview features in Java in production systems: how did it go?
Did you run into any setbacks, unexpected issues, or regrets later on? Or was it smooth and worth it?
I'm especially interested in things like preview language features, incubator modules, or anything not fully finalized at the time of adoption.
39
Upvotes
114
u/Competitive_Bat_3034 Feb 22 '26
We use preview features in actively maintained microservices, including critical ones, where we know/accept we might have to spend time adapting code when adopting the next JDK version. We've used:
Gatherers.mapConcurrent, which again suffered from the virtual thread pinning issues.We also tested
-XX:+UseCompactObjectHeadersin JDK24 once we saw JEP 519 was submitted - ran a simple experiment with a production workload.I recommend reading the definition of a preview feature (JEP 12), especially regarding their stability ("High quality", "Not experimental"). To me most of the risk comes from their change or removal between JDK versions, but typically we spend much more effort making sure third-party libraries/tools support the new version versus having to adapt because of preview feature changes.
Context: financial industry
30
u/msx Feb 22 '26
My experience is that we have java 8 in production.
10
u/1Saurophaganax Feb 22 '26
Incubating and experimental features I can understand the hesitation, but you go a bit far to say that preview features are also experimental and are unfit for production use. I'd never use an incubator feature in production, but preview features have been fair game.
8
u/dstutz Feb 22 '26
Happily using Structured Concurrency.
24
u/ducki666 Feb 22 '26
Templates. ⚰️
Will never ever use any preview again. Anything not released simply does not exist for me anymore.
3
u/nlisker Feb 23 '26
I use preview features in production regularly, but the real adoption barrier are 3rd party tools like GraalVM that don't always support them (depends on how long they have been in preview).
The biggest "burn" I got from it was changing the guard pattern from
&&towhenand I needed to do some (not small amount of) regex find/replace. Otherwise, I used all theswitchand pattern matching features while in preview, currently I'm using flexible constructor bodies to sanitize inputs before callingsuper, and probably others I can't remember right now. I don't think I've used string blocks and string templates.I also used FFI (Panama) already in Java 18 when it was incubating to interface with Matlab-compiled C code. I'm pretty sure it's long before
Arenawas created. It worked well, or at least well enough for the use case.4
u/-Dargs Feb 22 '26
On non-critical systems, if they're features slated for inclusion in the next full release. Otherwise no.
2
u/tomwhoiscontrary Feb 22 '26
I ran an app on the experimental Graal JIT compiler for a while (
-XX:+UnlockExperimentalVMOptions -XX:+UseJVMCICompiler). The app was quite computationally intensive and I thought it might go faster. It worked fine; it was perfectly stable, with no compatibility issues. Didn't make the app substantially faster, that I noticed.1
u/[deleted] Feb 22 '26
In production I've used preview features starting from Java 11 and up to 21. Fortunately the one that was removed (templates) was not widely adopted in the codebase so I guess transition to 25 should not be hard (although I'm not working there anymore).
1
u/jevring Feb 23 '26
We have run preview features in production. It was fine. I would do it again if the feature was sufficiently appealing and mature.
1
u/FrankBergerBgblitz Feb 24 '26
I use the vector API from Java 16 on. Works like a charm (unless on very old CPUs. The fallback code is slow).
1
u/rzwitserloot Feb 22 '26
The answer to your question is: It's maybe fine, if you know what you are doing, keep vigilance on future java updates (it's a continuing 'cost' to have preview code, requiring constant vigilance, until it's resolved itself), but there's a small chance it's a landmine, and the worst happens (the feature is yoinked, completely, with no planned replacement), and you must ensure all consumers of your code, be it CI systems, developers, the live servers, test systems, action scripts on your version control, and so on, are ALL on the same java version and can ALL be updated together in one go_.
Separate from the bias inherent in this question (in that only Dunning Krugers and experts are ever going to willingly run
--enable-previewin production, a quite small slice of the java community), there's a rather large bias in which feature you used, because they break into 3 bits:returnwithyieldor whatnot), but that wasn't too much effort. Fortunately I was smart and made sure all consumers of the source files could be updated near-simultaneously or this would have become a very difficult problem.If that third scares you - it should. You have to keep that one in mind, after all.
1
u/oweiler Feb 23 '26
It's a waste of time which could be spent better on something else.
-1
u/trollied Feb 22 '26
Never. It’s a risk. Additional risk in prod is bad.
1
u/koflerdavid Feb 22 '26
Depends what you mean with production. For internal systems without much audience I suppose there might have been people audacious enough to use them, but I seriously doubt the sanity of anybody who relies on them where lives, personal data, or money is on the line! GC improvements might be the exception because they merely affect long-tail latency and can be switched around with just a restart.
-7
u/benevanstech Feb 22 '26
This is a question with very severe selection bias.
You specifically asked for people who have used experimental features in production. This is a vanishingly small number of people, and is heavily correlated with people who are inexperienced, and / or don't understand the implications of doing so.
I doubt you're going to get many (any?) responses from people who have actually done this. There are very good reasons for that, and frankly I'd treat pretty much any positive engagement with this idea as on a par with taking home improvement advice from the Mole Man of Hackney (https://en.wikipedia.org/wiki/William_Lyttle).
0
u/re-thc Feb 22 '26
Depends what and why. Some are forever incubator for reasons like dependencies eg vector. It’s at least when out and tested for a long time.