2548N/A/*
3399N/A * Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved.
2548N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
2548N/A *
2548N/A * This code is free software; you can redistribute it and/or modify it
2548N/A * under the terms of the GNU General Public License version 2 only, as
2548N/A * published by the Free Software Foundation. Oracle designates this
2548N/A * particular file as subject to the "Classpath" exception as provided
2548N/A * by Oracle in the LICENSE file that accompanied this code.
2548N/A *
2548N/A * This code is distributed in the hope that it will be useful, but WITHOUT
2548N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
2548N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
2548N/A * version 2 for more details (a copy is included in the LICENSE file that
2548N/A * accompanied this code).
2548N/A *
2548N/A * You should have received a copy of the GNU General Public License version
2548N/A * 2 along with this work; if not, write to the Free Software Foundation,
2548N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
2548N/A *
2548N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2548N/A * or visit www.oracle.com if you need additional information or have any
2548N/A * questions.
2548N/A */
2548N/A
2548N/Apackage java.lang;
2548N/A
2548N/A/**
2548N/A * A resource that must be closed when it is no longer needed.
2548N/A *
2548N/A * @author Josh Bloch
2548N/A * @since 1.7
2548N/A */
2548N/Apublic interface AutoCloseable {
2548N/A /**
3399N/A * Closes this resource, relinquishing any underlying resources.
3757N/A * This method is invoked automatically on objects managed by the
3757N/A * {@code try}-with-resources statement.
3757N/A *
3757N/A * <p>While this interface method is declared to throw {@code
3757N/A * Exception}, implementers are <em>strongly</em> encouraged to
3757N/A * declare concrete implementations of the {@code close} method to
3757N/A * throw more specific exceptions, or to throw no exception at all
3757N/A * if the close operation cannot fail.
2548N/A *
3757N/A * <p><em>Implementers of this interface are also strongly advised
3757N/A * to not have the {@code close} method throw {@link
3757N/A * InterruptedException}.</em>
3757N/A *
3757N/A * This exception interacts with a thread's interrupted status,
3757N/A * and runtime misbehavior is likely to occur if an {@code
3757N/A * InterruptedException} is {@linkplain Throwable#addSuppressed
3757N/A * suppressed}.
3757N/A *
3757N/A * More generally, if it would cause problems for an
3757N/A * exception to be suppressed, the {@code AutoCloseable.close}
3757N/A * method should not throw it.
2548N/A *
2607N/A * <p>Note that unlike the {@link java.io.Closeable#close close}
2607N/A * method of {@link java.io.Closeable}, this {@code close} method
2607N/A * is <em>not</em> required to be idempotent. In other words,
2607N/A * calling this {@code close} method more than once may have some
2607N/A * visible side effect, unlike {@code Closeable.close} which is
2607N/A * required to have no effect if called more than once.
2607N/A *
3757N/A * However, implementers of this interface are strongly encouraged
3757N/A * to make their {@code close} methods idempotent.
3399N/A *
2548N/A * @throws Exception if this resource cannot be closed
2548N/A */
2548N/A void close() throws Exception;
2548N/A}