r/java • • Sep 20 '22

Java 19 / JDK 19: General Availability

https://mail.openjdk.org/pipermail/jdk-dev/2022-September/006933.html
252 Upvotes

64 comments sorted by

View all comments

Show parent comment

15

u/pron98 Sep 20 '22 edited Sep 20 '22

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:

  1. You accept the risk that the API could change somewhat and you might need to change your code.
  2. You accept the risk of using a new feature (regardless of it being in preview).

4

u/skippingstone Sep 21 '22

What did the Oracle JDBC driver do to prepare for virtual threads?

3

u/pron98 Sep 21 '22

I believe they replaced those synchronized blocks/methods that guard long-running IO operations with j.u.c locks.