com.hazelcast.util

## Class ConcurrencyUtil

- java.lang.Object
- - com.hazelcast.util.ConcurrencyUtil

-     public final class ConcurrencyUtil
      extends Object

  Utility methods to getOrPutSynchronized and getOrPutIfAbsent in a thread safe way from a `ConcurrentMap` with a `ConstructorFunction`.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static Executor` | `CALLER_RUNS` The Caller runs executor is an Executor that executes the task on the calling thread.

  - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static <K,V> V` | `getOrPutIfAbsent(ConcurrentMap<K,V> map, K key, ConstructorFunction<K,V> func)`
    `static <K,V> V` | `getOrPutSynchronized(ConcurrentMap<K,V> map, K key, ContextMutexFactory contextMutexFactory, ConstructorFunction<K,V> func)`
    `static <K,V> V` | `getOrPutSynchronized(ConcurrentMap<K,V> map, K key, Object mutex, ConstructorFunction<K,V> func)`
    `static boolean` | `setIfEqualOrGreaterThan(AtomicLong oldValue, long newValue)`
    `static <E> void` | `setMax(E obj, AtomicLongFieldUpdater<E> updater, long value)` Atomically sets the max value.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### CALLER_RUNS

          public static final Executor CALLER_RUNS

      The Caller runs executor is an Executor that executes the task on the calling thread. This is useful when an Executor is required, but offloading to a different thread is very costly and it is faster to run on the calling thread.

  - ### Method Detail

    - #### setMax

          public static <E> void setMax(E obj,
                                        AtomicLongFieldUpdater<E> updater,
                                        long value)

      Atomically sets the max value. If the current value is larger than the provided value, the call is ignored. So it will not happen that a smaller value will overwrite a larger value.

    - #### setIfEqualOrGreaterThan

          public static boolean setIfEqualOrGreaterThan(AtomicLong oldValue,
                                                        long newValue)

    - #### getOrPutSynchronized

          public static <K,V> V getOrPutSynchronized(ConcurrentMap<K,V> map,
                                                     K key,
                                                     Object mutex,
                                                     ConstructorFunction<K,V> func)

    - #### getOrPutSynchronized

          public static <K,V> V getOrPutSynchronized(ConcurrentMap<K,V> map,
                                                     K key,
                                                     ContextMutexFactory contextMutexFactory,
                                                     ConstructorFunction<K,V> func)

    - #### getOrPutIfAbsent

          public static <K,V> V getOrPutIfAbsent(ConcurrentMap<K,V> map,
                                                 K key,
                                                 ConstructorFunction<K,V> func)

Copyright © 2019. All rights reserved.