Class LockFreePool<T>

java.lang.Object
org.graalvm.collections.LockFreePool<T>
Type Parameters:
T - Type of the elements in this pool.

public class LockFreePool<T> extends Object
Concurrent lock-free pool data structure.

Supports two operations -- adding an element, and removing an element. The add(Object) operation adds an element into the pool. The get() operation returns one of the elements previously added to the pool. There is no guarantee about the order in which the elements are returned by get(). The guarantee is that an element will only be returned by get() as many times as it was previously added to the pool by calling add(Object). If there are no more elements to return, it will return null. Both operations are lock-free and linearizable -- this data structure is intended for use by multiple threads. The internal implementation is a simple Treiber stack.

Since:
23.0
  • Constructor Details

    • LockFreePool

      public LockFreePool()
      Since:
      23.0
  • Method Details

    • get

      public T get()
      Returns a previously added element.

      This method returns a previously added element only once to some caller. If the element was added multiple times, calling this method will return that element as many times before returning null. This method does not do any object allocations.

      Returns:
      A previously added element, or null if there are no previously added elements that have not been already returned.
      Since:
      23.0
    • add

      public void add(T element)
      Adds an element to this pool.

      An element can be added multiple times to the pool, but in this case may be returned as many times by get(). This method internally allocates objects on the heap.

      Parameters:
      element - An element to add to the pool.
      Since:
      23.0