T - the type of the shared resourcepublic class SharedReleaser<T extends java.lang.AutoCloseable>
extends java.lang.Object
implements java.lang.AutoCloseable
AutoCloseable to release() a
SharedResource exactly once when an instance of this is
closed. This is convenient for translating reference counting into
AutoCloseble so that java try-with-resource can be used to manage
reference counting.| Constructor and Description |
|---|
SharedReleaser(SharedResource<T> sharedResource)
Constructor.
|
| Modifier and Type | Method and Description |
|---|---|
void |
close() |
T |
get()
Get the resource.
|
SharedResource<T> |
getSharedResource()
Get the SharedResource.
|
public SharedReleaser(SharedResource<T> sharedResource)
sharedResource - the SharedResource to be released when this is close()d.public void close()
close in interface java.lang.AutoCloseablepublic SharedResource<T> getSharedResource()
SharedResource.addRef().)public T get()