Fwd: AutoCloseable blocking or not

Alan Bateman Alan.Bateman at oracle.com
Fri Oct 5 09:56:46 UTC 2012


Forwarding Kasper's mail to the right list.

-------- Original Message --------
Subject: 	AutoCloseable blocking or not
Date: 	Fri, 5 Oct 2012 11:42:35 +0200
From: 	Kasper Nielsen <kasperni at gmail.com>
To: 	nio-discuss at openjdk.java.net



Hi,

I have a question about the AutoCloseable interface. Since I cannot
find any mention about how asynchronously closeable resources should
be handled.

Say I wanted juc.ThreadPoolExecutorService to implement AutoCloseable.
When close() returned should the executor be in the shutdown phase or
in the terminated phase?

In other words should I implement close() like this (which I believe)

public void close() {
  executor.shutdown();
  executor.awaitTermination(Long.MAX_VALUE, TimeUnit.SECONDS); //ignore
any interrupted exceptions
}

or like this

public void close() {
  executor.shutdown();
}

- Kasper




More information about the core-libs-dev mailing list