public interface ManagedCloseable extends Closeable
ManagedCloseable interface extends the Closeable interface and provides additional methods
that are primarily intended for expert use cases involving resource lifecycle management.
This interface is designed for scenarios where more fine-grained control over the closing process of a resource is needed, or where it is necessary to perform advanced operations based on the state of the resource.
| Modifier and Type | Method and Description |
|---|---|
default StackTrace |
createdHere()
Returns the stack trace of the location where the resource was created.
|
default void |
throwExceptionIfClosed()
Throws an exception if the resource is closed or in the process of closing.
|
default void |
warnAndCloseIfNotClosed()
Closes the resource if it is not already closed, and logs a warning if the resource was discarded without being closed.
|
close, closeQuietly, closeQuietlyisClosed, isClosingdefault void warnAndCloseIfNotClosed()
When resource tracing is enabled and discard warnings are not disabled, a warning message is logged indicating that the resource was discarded without being properly closed. The resource is then closed quietly, meaning that no exception is thrown if an error occurs during the closing process.
default void throwExceptionIfClosed()
throws ClosedIllegalStateException,
ThreadingIllegalStateException
If the resource is in the process of closing, a ClosedIllegalStateException is thrown.
The exception message indicates whether the resource is already closed or is currently in the process of closing.
ClosedIllegalStateException - If the resource has been released or closed.ThreadingIllegalStateException - If the thread safety check fails.default StackTrace createdHere()
By default, this method returns null, indicating that the information is not available.
Implementations may override this method to provide the actual stack trace where the resource was created.
null if the information is not available.Copyright © 2024. All rights reserved.