Top Description Inners Fields Constructors Methods
org.graalvm.collections

public Class LockFreePool<T>

extends Object
Class Inheritance
Type Parameters
<T>
Type of the elements in this pool.
Imports
java.util.concurrent.atomic.AtomicReference

Concurrent lock-free pool data structure.

Supports two operations -- adding an element, and removing an element. The LockFreePool#add(Object) operation adds an element into the pool. The LockFreePool#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 LockFreePool#get(). The guarantee is that an element will only be returned by LockFreePool#get() as many times as it was previously added to the pool by calling LockFreePool#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

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
LockFreePool.Node<E>

Internal wrapper node used to wrap the element and the tail pointer.

Field Summary

Modifier and TypeField and Description
private final AtomicReference<LockFreePool.Node<T>>
head

The top-of-the-Treiber-stack pointer.

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
add(T
An element to add to the pool.
element
)

Adds an element to this pool.

public T

Returns:

A previously added element, or null if there are no previously added elements that have not been already returned.
get
()

Returns a previously added element.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

Constructor Detail

LockFreePoolback to summary
public LockFreePool()
Since
23.0

Method Detail

addback to summary
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 LockFreePool#get(). This method internally allocates objects on the heap.

Parameters
element:T

An element to add to the pool.

Since
23.0
getback to summary
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:T

A previously added element, or null if there are no previously added elements that have not been already returned.

Since
23.0
org.graalvm.collections back to summary

private final Class LockFreePool.Node<E>

extends Object
Class Inheritance

Internal wrapper node used to wrap the element and the tail pointer.

Field Summary

Modifier and TypeField and Description
pack-priv final E
element

Element stored in this node.

pack-priv final LockFreePool.Node<E>
tail

Pointer to the tail of the linked list, or null if the end of the list.

Constructor Summary

AccessConstructor and Description
private
Node(E element, LockFreePool.Node<E> tail)

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

elementback to summary
pack-priv final E element

Element stored in this node.

tailback to summary
pack-priv final LockFreePool.Node<E> tail

Pointer to the tail of the linked list, or null if the end of the list.

Constructor Detail

Nodeback to summary
private Node(E element, LockFreePool.Node<E> tail)