Class ReferenceCountingResourceHolder<T>

    • Constructor Detail

      • ReferenceCountingResourceHolder

        public ReferenceCountingResourceHolder​(T object,
                                               Closeable closer)
    • Method Detail

      • leakedResources

        public static long leakedResources()
      • get

        public T get()
        Returns the resource with an initial reference count of 1. More references can be added by calling increment().
        Specified by:
        get in interface ResourceHolder<T>
      • increment

        public ResourceHolder<T> increment()
        Increments the reference count by 1 and returns a ResourceHolder representing the new references. The returned ResourceHolder "close" method decrements the reference count when the caller no longer needs the resource. Returned ResourceHolder are not thread-safe. If multiple threads need references to the same resource, they should each call this method on the original object.