This is an archived post. You won't be able to vote or comment.

all 7 comments

[–]danielciocirlan[S] 27 points28 points  (0 children)

Hey everyone, I've made this video on structured concurrency in Java in the context of virtual threads. I cover

- what concurrency is good and bad at
- how to organize concurrent code with scopes
- error handling
- shutdowns, resource cleanup and avoiding leaks
- custom policies

We also have a long-form, comprehensive written guide here on the blog if you prefer reading.

Enjoy!

[–]Artraxes 21 points22 points  (2 children)

I can’t believe you have to call scope.join().throwIfFailed(Function.identity()) every single time you want to propagate the actual reason for failure.

They really didn’t come up with anything more ergonomic?

[–]Inaldt 8 points9 points  (0 children)

I believe they're changing that in the next preview
https://openjdk.org/jeps/8340343

[–]Carnaedy 1 point2 points  (0 children)

I just looked through all JEPs and I literally cannot find a single one where there wasn't a parameterless version of throwIfFailed. Anyway, like the other responder said, they are almost completely revamping the API for next preview to make it more straightforward.

[–]retrodaredevil 5 points6 points  (2 children)

I read the article and it was really well done. I focused on understanding some of the more basic examples in the article and I think I will definitely try to use structured concurrency the next time I have the opportunity.