In two weeks, #Java19 will be released with some of Java's most anticipated features: virtual threads and structured concurrency! 🤩
To make the best use of virtual threads, servers/frameworks need to support them - here's a list of those that do (reply with those I missed). 🧵
📣 All of this is still experimental!
Virtual threads and the new APIs are (you need `--enable-preview` and the incubator module `jdk.incubator.concurrent` to use them) and so is support in these projects. You can help them mature over the next months by testing with your app.
The @JakartaEE server @TheApacheTomcat provided experimental support as a part of their 10.1.0-M16 release back in June, but there was a bug that broke HTTP/2 support if async IO was disabled. The unreleased 10.1.0-M17 will include a fix.
The async Java-based HTTP server @JettyProject merged changes to support Loom in github.com/eclipse/jetty.…. It will be part of their 10.0.x release train, likely 10.0.12.
But it does one better! 4.0 will come with a Nima (github.com/oracle/helidon…), a server written entirely around virtual threads with similar performance as Netty. Follow @helidon_project for updates!
Supersonic, subatomic Java server @QuarkusIO merged virtual thread support in May (github.com/quarkusio/quar…), which was released in version 2.10.0 in June.
IDEs will work out of the box with virtual threads but could improve in at least two ways:
➀ Find a better way to select a thread than showing a drop-down box with potentially millions of them. 😬
➁ Show the relationship between them that's created by structured concurrency.
I know some IDEs have an issue that you can track, but as far as I can tell, they're not yet very active:
Changes:
* constant case labels must now appear before guarded patterns of the same type
* exhaustiveness checking is now more precise when sealed classes and generics mix
#ProjectLoom's virtual threads will make high performance in concurrent systems attainable with much simpler code. But Loom aims for even more and wants to make the code clearer and more robust by introducing *structured concurrency*.
Here's what that's all about. 🧵
Important: This is about concurrency, not parallelism. See yesterday's thread 👇🏾 for a more detailed distinction, but the gist is that concurrency is about processing lots of tasks that the environment throws at your system at the same time, ideally with high throughput.
* splitting and joining concurrent subtasks in different methods/classes
* little support to compose error-handling, cancellation, … across subtasks
* threading structure is opaque to the runtime, which only sees independent threads
* …
I'm no security expert and don't know how ubiquitous this vulnerability is, but if you use Log4J 2.x, you should probably update to 2.15.x and read these:
From compact record constructors to pattern matching, from generic wildcards to chaining predicates and comparators, from jpackage to jlink - here are 11 #Java tricks handpicked from dev.java. 🧵
(Musical version of this thread: )
0/11
A #record's *canonical* constructor has one arg per component but in its *compact* form, you don't have to list them. You also don't have to (in fact, can't) assign fields, just do the checks/reassignments you need, rest happens automatically.
Serialization works great with #records, no black magic needed! The guaranteed presence of constructor parameters and accessors makes serialization work with the object model and makes it easy to create reliable serializable records.
Here are 11 improvements you get when updating to #Java16 later today: from records and type patterns to `Stream`-additions and Unix domain sockets, from creating installers to more performance and observability. 🧵👇🏾
Express in a single line that a type is just a collection of data without need for encapsulation and let the compiler do the rest:
record Range(int low, int high) { }
That results in almost the same API as the attached class. *drops mic*
#2 Type Pattern Matching
This is actually two-for-one:
* first step into pattern matching
* type patterns with `instanceof`
With a type pattern you check whether a variable is of a certain type and, if so, create a new variable of that type, so you can use it without casting.