class RefCountResource {

    public void release() throws RefCountResourceException {
        synchronized (this) {
            if (refCount.updateAndGet(i -> i > 0 ? i - 1 : i) == 0 && resource.get() != null) {
                log.debug("No more References. Cleanup Resource: {}", resource.get());
                try {
                    resourceCleanup.accept(resource.getAndSet(null));
                }
                catch (Throwable throwable) {
                    throw new RefCountResourceException(throwable);
                }
            }
        }
    }

    public  RefCountResource(Supplier<? extends T> resourceSupplier,
                            Consumer<? super T> resourceCleanup);
      RefCountResource(Supplier<? extends T> resourceSupplier,
                     Consumer<? super T> resourceCleanup,
                     AtomicInteger refCount,
                     AtomicReference<T> resource);

}