r/java 4d ago

JEP draft: Structured Concurrency

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

18 comments sorted by

View all comments

9

u/javaprof 4d 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? 
   }
}

21

u/pron98 4d ago edited 4d 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.