AutoCloseable blocking or not

Alan Bateman Alan.Bateman at oracle.com
Fri Oct 5 02:59:12 PDT 2012


I have forwarded your mail to the core-libs-dev list.

On 05/10/2012 10:42, Kasper Nielsen wrote:
> 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 nio-discuss mailing list