Class ObjectsPool<T>


  • public class ObjectsPool<T>
    extends Object
    Auto-cleanable thread-safe implementation for deduplicate any objects (according to equals&hashcode methods). Use reuse(Object) method for deduplication. The cache uses WeakHashMap for storing duplicates, it stores same instance in key and value in weak references. So on reuse, it gets existing instance from map or puts if there are no instance and returns it. If deduplicated object is not reachable in application via strong reference GC will remove weak-reachable instances and standard java WeakHashMap implementation will remove map entry
    Since:
    2024.07
    • Constructor Detail

      • ObjectsPool

        public ObjectsPool()
    • Method Detail

      • reuse

        @NotNull
        public T reuse​(@NotNull
                       T value)