#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
* …
That makes it hard for devs to write and maintain concurrent code. And debugging/monitoring suffers as well because the runtime doesn't see the structure.
The underlying problem is that the building blocks are too general and technical - they lack semantics.
Software development was in that situation before, most notably with GOTO et al vs structured programming (en.wikipedia.org/wiki/Structure…). GOTO lead to endless spaghetti, so structured programming constructs that were both more *limited* and more *semantic*.
Martin Sústrik introduced the same idea for concurrency in 250bpm.com/blog:71/ :
"Structured concurrency is similar to […] structured programming […]. [It] prevents random jumping around the codebase and instead structures the program as a set of nested code blocks."
That inspired Project Loom's approach - an API that:
* makes it easy to start and join subtasks in the same block
* prevents threads from escaping the scope
* allows easy error-handling across them
* captures task/subtask hierarchy for easier debugging and monitoring
The draft JEP (openjdk.java.net/jeps/8277129) proposes an API that can already be experimented with in the Loom EA builds (jdk.java.net/loom/). If you can gather some practical experience (e.g. refactoring a project), sharing it on the mailing list would be very welcome.
🏁
PS: The latest Inside Java Newscast () discusses this topic in a bit more detail. If you want a lot more detail check the JEP (👆🏾), Sústrik's post (👆🏾👆🏾) and, if you still don't have enough, this one by @vorpalsmith: vorpus.org/blog/notes-on-…
• • •
Missing some Tweet in this thread? You can try to
force a refresh
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.
That's a guiding light of #ProjectAmber and record serialization is the first step. The Inside Java Podcast episode on that topic with Julia Boes and @chegar999 (inside.java/2021/03/08/pod…) gives great insight into how it achieves that. 🧵
1/10
First, what's wrong with regular serialization? In short:
* extralinguistic mechanism (aka "magic")
* undermines encapsulation
* causes security issues
* hinders evolving code
* holds back new Java features
In long (and why it turned out that way), see attached thread.
Do you dream of "value types" in Java? So do I! Hence I was thrilled to see that Project Valhalla is slowly coming out of exploration with two draft JEPs.
Here's what they currently propose. 🧵👇🏾
(If you prefer video: https:/www.youtube.com/watch?v=WBvTilbh8S0&t=344s)
1/10
First, why value types? To bridge the divide between
* primitives (fast, no memory overhead) and
* reference types (abstraction, safety, identity)
As is, we sometimes have to choose between performance and design. And we often choose wrongly.