Class WeakConcurrentMap<K,​V>

  • All Implemented Interfaces:
    Iterable<Map.Entry<K,​V>>, Runnable
    Direct Known Subclasses:
    WeakConcurrentMap.WithInlinedExpunction

    public class WeakConcurrentMap<K,​V>
    extends AbstractWeakConcurrentMap<K,​V,​io.opentelemetry.context.internal.shaded.WeakConcurrentMap.LookupKey<K>>
    A thread-safe map with weak keys. Entries are based on a key's system hash code and keys are considered equal only by reference equality. This class does not implement the Map interface because this implementation is incompatible with the map contract. While iterating over a map's entries, any key that has not passed iteration is referenced non-weakly.

    This class has been copied as is from https://github.com/raphw/weak-lock-free/blob/ad0e5e0c04d4a31f9485bf12b89afbc9d75473b3/src/main/java/com/blogspot/mydailyjava/weaklockfree/WeakConcurrentMap.java This is used in multiple artifacts in OpenTelemetry and while it is in our internal API, generally backwards compatible changes should not be made to avoid a situation where different versions of OpenTelemetry artifacts become incompatible with each other.

    • Constructor Detail

      • WeakConcurrentMap

        public WeakConcurrentMap​(boolean cleanerThread)
        Parameters:
        cleanerThread - true if a thread should be started that removes stale entries.
      • WeakConcurrentMap

        public WeakConcurrentMap​(boolean cleanerThread,
                                 boolean reuseKeys)
        Parameters:
        cleanerThread - true if a thread should be started that removes stale entries.
        reuseKeys - true if the lookup keys should be reused via a ThreadLocal. Note that setting this to true may result in class loader leaks. See isPersistentClassLoader(ClassLoader) for more details.
      • WeakConcurrentMap

        public WeakConcurrentMap​(boolean cleanerThread,
                                 boolean reuseKeys,
                                 ConcurrentMap<AbstractWeakConcurrentMap.WeakKey<K>,​V> target)
        Parameters:
        cleanerThread - true if a thread should be started that removes stale entries.
        reuseKeys - true if the lookup keys should be reused via a ThreadLocal. Note that setting this to true may result in class loader leaks. See isPersistentClassLoader(ClassLoader) for more details.
        target - ConcurrentMap implementation that this class wraps.