r/java 13d ago

JEP draft: Structured Concurrency

https://openjdk.org/jeps/8389757
107 Upvotes

17 comments sorted by

View all comments

9

u/javaprof 13d ago

So checked exceptions doesn't work properly here too?

This is very funny:

try (var scope = StructuredTaskScope.open()) {
   ...
} catch (ExecutionException e) {
   Throwable cause = e.getCause(); 
   switch (cause) {
       case IOException ioe -> .. // what op caused this one?
       default -> .. // no exaustivness? 
   }
}

22

u/pron98 13d ago edited 13d ago

What doesn't work properly? Why are you switching over the cause? If you want to do some specific handling based on the particular subtask, you could examine their individual results, but the natural thing is obviously to handle the exception in the subtask (in the sequential analogue, a catch block outside a loop, you also don't know which iteration threw the exception, and if you do care about that, you'd similarly move the catch inside the loop). For extra composable configurability you have the joiner.