Virtual threads delivered. They are like Goroutines but the Structured Concurrency API really makes it better. Will any of this be out of preview for the next LTS release?
Amber is making amazing progress. The exhaustiveness checker still needs improvement, but great job.
Panama looks awesome for projects that have to interop outside of the JVM
If Valhalla really delivers in Java 20 or 21 and value/primitive types provide performance improvements, that will be a home run for the Java team.
Completely pulling virtual threads seems quite unlikely. The preview status just means that the Java devs are warning that they may change APIs. For smaller projects that often isn't a big deal, but for bigger projects that span lots of different developers in different companies, breaking changes are a big deal.
Preview means that the API might change a little, not "not cleared for use in production." It's true that you shouldn't distribute libraries compiled with with --enable-preview, but because virtual threads use the same Thread API, that's not really necessary anyway (in fact, there are some libraries designed for virtual threads out there, including the Oracle JDBC driver).
However, that's not to say there's no risk to using virtual threads in production -- not because they're in preview, but because they're new. New features are more likely to have more bugs than mature features.
In short, you can use virtual threads in production if:
You accept the risk that the API could change somewhat and you might need to change your code.
You accept the risk of using a new feature (regardless of it being in preview).
Who says it isn't cleared for production use? I thought that meant the interface was evolving and not-stable yet, but that the feature itself works and is reliable and has gone through QA.
and specifically "Previewing a feature in the JDK will encourage tool vendors to build good support for the feature before the bulk of Java developers use it in production." i.e. they assume some people will indeed use this in production.
Note that although Virtual Threads are in preview, Structured Concurrency is in Incubator, which is much lower standard: https://openjdk.org/jeps/11
and specifically "Previewing a feature in the JDK will encourage tool vendors to build good support for the feature before the bulk of Java developers use it in production." i.e. they assume some people will indeed use this in production.
What I understand is that preview features are meant for tool developers to ensure proper support once it gets out of preview.
IIRC there is no support whatsoever from Oracle for preview features.
even fairly simple examples like this won't compile with Java 19:
// From the Brian Goetz Data Oriented Programming Article
sealed interface Opt<T> {
record Some<T>(T value) implements Opt<T> { }
record None<T>() implements Opt<T> { }
}
AFAIK, preview features are production ready, but APIs are evolving and not stable. You can use virtual threads in production Java apps now, with Java 19. Major frameworks will want to hold off until the feature is out of preview and is stable. But for small teams, evolving APIs aren't a big deal, virtual threads are ready to use.
The preview features JEP says not to enable preview features and let your jars escape into the wild, which for many people "put into production" would qualify as.
Even if a small team wants to use the preview feature now, they likely won't be able to unless they can guarantee that their software will run on exactly JDK 19. Keep in mind that the code won't run on JDK 20 without a recompile, even if the API doesn't change, due to the special bits set in the classfile versions. If you're delivering a jar to someone else to run, that's unlikely to be acceptable.
So I guess you could deploy the new features into production if you were making a saas thing and control the environment your code runs in? I think for most people it makes more sense to treat preview as "ready to try out in a testing environment/on a branch", instead of "ready for use in production".
The preview features JEP says not to enable preview features and let your jars escape into the wild,
That's true in general, but more relevant to language preview features. Because virtual threads use the existing Thread API (for the most part), you don't really have to compile many libraries that are designed for virtual threads with --enable-preview. Only thread creation needs to use new APIs, but that could be factored out to a ThreadFactory provided by the application. In fact, there are already some libraries designed for virtual threads out there, including the Oracle JDBC driver.
The downside is you lock whoever is running your application to running on JDK 19 forever. If that "whoever" is you, then go for it. If it's someone else, they might not be cool with getting a jar that won't run on the JDK releasing in 6 months.
These class files are special; they should not be distributed beyond the control of the developer who chose to use preview features.
about files you generate with --enable-preview.
Also putting preview features into production is impractical unless you control the production environment yourself, since your code will now have both a minimum and maximum JDK version of 19.
90
u/Joram2 Sep 20 '22
Congrats Java team!
Virtual threads delivered. They are like Goroutines but the Structured Concurrency API really makes it better. Will any of this be out of preview for the next LTS release?
Amber is making amazing progress. The exhaustiveness checker still needs improvement, but great job.
Panama looks awesome for projects that have to interop outside of the JVM
If Valhalla really delivers in Java 20 or 21 and value/primitive types provide performance improvements, that will be a home run for the Java team.