close()
method of an AutoCloseable
object is called automatically when exiting a try
-with-resources block for which the object has been declared in
the resource specification header. This construction ensures prompt
release, avoiding resource exhaustion exceptions and errors that
may otherwise occur.
API Note
It is possible, and in fact common, for a base class to
implement AutoCloseable even though not all of its subclasses or
instances will hold releasable resources. For code that must operate
in complete generality, or when it is known that the AutoCloseable
instance requires resource release, it is recommended to use try
-with-resources constructions. However, when using facilities such as
java.
that support both I/O-based and
non-I/O-based forms, try
-with-resources blocks are in
general unnecessary when using non-I/O-based forms.
Modifier and Type | Method and Description |
---|---|
public void |
close | back to summary |
---|---|
public void close() throws Exception Closes this resource, relinquishing any underlying resources.
This method is invoked automatically on objects managed by the
API Note While this interface method is declared to throw Cases where the close operation may fail require careful
attention by implementers. It is strongly advised to relinquish
the underlying resources and to internally mark the
resource as closed, prior to throwing the exception. The Implementers of this interface are also strongly advised
to not have the Note that unlike the
|