@ThreadSafe public final class SharedResourceHolder extends Object
Components like client channels and servers need certain resources, e.g. a thread pool, to run. If the user has not provided such resources, these components will use a default one, which is shared as a static resource. This class holds these default resources and manages their life-cycles.
A resource is identified by the reference of a
SharedResourceHolder.Resource object, which is typically a
singleton, provided to the get() and release() methods. Each Resource object (not its class) maps
to an object cached in the holder.
Resources are ref-counted and shut down after a delay when the ref-count reaches zero.
|Modifier and Type||Class and Description|
Defines a resource, and the way to create and destroy instances of it.
|Modifier and Type||Method and Description|
Try to get an existing instance of the given resource.
Releases an instance of the given resource.
public static <T> T get(SharedResourceHolder.Resource<T> resource)
resource- the singleton object that identifies the requested static resource
public static <T> T release(SharedResourceHolder.Resource<T> resource, T instance)
The instance must have been obtained from
get(Resource). Otherwise will throw
Caller must not release a reference more than once. It's advisory that you clear the reference to the instance with the null returned by this method.
resource- the singleton Resource object that identifies the released static resource
instance- the released static resource
Copyright © 2014–2023 The Apache Software Foundation. All rights reserved.