[External] : Re: A new build and a new structured concurrency API

Ron Pressler ron.pressler at oracle.com
Tue Nov 16 15:00:40 UTC 2021


Absolutely, we just didn’t want to tie this feature to language changes.
But I would hope to see this and possibly other improvements to try-with-resources.

— Ron

On 16 Nov 2021, at 14:33, Kasper Nielsen <kasperni at gmail.com<mailto:kasperni at gmail.com>> wrote:


If the language is changed to make AutoCloseable more flexible, this requirement
might be removed.

— Ron

Adding something like

default close(Throwable cause) {
  close();
}

to AutoClosable would also be beneficial for people working with
databases. Right now a lot of transactional code looks like this:

try (Transaction transaction = Transaction.start()) {
   ... do transactional work
   transaction.commit();
} catch (Throwable e) {
  transaction.rollback();
}

Which could be reduced to

try (Transaction transaction = Transaction.start()) {
   ... do transactional work
 }

If the Transaction instance could be notified that it was closed
exceptionally.

/Kasper




More information about the loom-dev mailing list