T - The type of the contained resourcepublic class WeakReferenceScopedResource<T> extends Object
ScopedResource when the resource is acquired, we create
a strong reference to prevent it being GC'd while it's "in use". Upon return, the
strong reference is cleared, leaving only the weak reference thus allowing the
resource to be GC'd.| Constructor and Description |
|---|
WeakReferenceScopedResource(ScopedThreadLocal<T> scopedThreadLocal,
Supplier<T> supplier) |
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Signifies the end of the scope, will return the resource to the "pool" for use by other acquirers
|
void |
closeResource()
Close the contained resource and clear any references
|
T |
get()
Get the contained resource
|
long |
getCreatedTimeNanos()
The time this resource was created
|
@Nullable Class<?> |
getType()
Get the type of object contained, may return null
|
public WeakReferenceScopedResource(ScopedThreadLocal<T> scopedThreadLocal, Supplier<T> supplier)
public T get()
ScopedResourcepublic void close()
ScopedResourceclose in interface Closeableclose in interface AutoCloseableclose in interface ScopedResource<T>public void closeResource()
@Nullable public @Nullable Class<?> getType()
public long getCreatedTimeNanos()
System.nanoTime() of creationCopyright © 2024. All rights reserved.