Class ManyToOneConcurrentLinkedQueue<E>
- Type Parameters:
E
- element type in the queue.
- All Implemented Interfaces:
Iterable<E>
,Collection<E>
,Queue<E>
Queue
that can be used from many producers and a single consumer.
This is a Java port of Dmitry Vyukov's MPSC linked queue.
Note: This queue breaks the contract for peek and poll in that it can return null when the queue has no item available but size could be greater than zero if an offer is in progress. This is due to the offer being a multiple step process which can start and be interrupted before completion, the thread will later be resumed and the offer process completes. Other methods, such as peek and poll, could spin internally waiting on the offer to complete to provide sequentially consistency across methods but this can have a detrimental effect in a resource starved system. This internal spinning eats up a CPU core and prevents other threads making progress resulting in latency spikes. To avoid this a more relaxed approach is taken in that an in-progress offer is not waited on to complete.
If you wish to check for empty then call isEmpty()
rather than size()
checking for zero.
-
Nested Class Summary
Nested classes/interfaces inherited from class org.agrona.concurrent.ManyToOneConcurrentLinkedQueuePadding1
ManyToOneConcurrentLinkedQueuePadding1.Node<E>
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final ManyToOneConcurrentLinkedQueuePadding1.Node
<E> (package private) byte
(package private) byte
(package private) byte
(package private) byte
(package private) byte
(package private) byte
(package private) byte
(package private) byte
(package private) byte
(package private) byte
(package private) byte
(package private) byte
(package private) byte
(package private) byte
(package private) byte
(package private) byte
(package private) byte
(package private) byte
(package private) byte
(package private) byte
(package private) byte
(package private) byte
(package private) byte
(package private) byte
(package private) byte
(package private) byte
(package private) byte
(package private) byte
(package private) byte
(package private) byte
(package private) byte
(package private) byte
(package private) byte
(package private) byte
(package private) byte
(package private) byte
(package private) byte
(package private) byte
(package private) byte
(package private) byte
(package private) byte
(package private) byte
(package private) byte
(package private) byte
(package private) byte
(package private) byte
(package private) byte
(package private) byte
(package private) byte
(package private) byte
(package private) byte
(package private) byte
(package private) byte
(package private) byte
(package private) byte
(package private) byte
(package private) byte
(package private) byte
(package private) byte
(package private) byte
(package private) byte
(package private) byte
(package private) byte
(package private) byte
Fields inherited from class org.agrona.concurrent.ManyToOneConcurrentLinkedQueueHead
head
Fields inherited from class org.agrona.concurrent.ManyToOneConcurrentLinkedQueuePadding2
p064, p065, p066, p067, p068, p069, p070, p071, p072, p073, p074, p075, p076, p077, p078, p079, p080, p081, p082, p083, p084, p085, p086, p087, p088, p089, p090, p091, p092, p093, p094, p095, p096, p097, p098, p099, p100, p101, p102, p103, p104, p105, p106, p107, p108, p109, p110, p111, p112, p113, p114, p115, p116, p117, p118, p119, p120, p121, p122, p123, p124, p125, p126, p127
Fields inherited from class org.agrona.concurrent.ManyToOneConcurrentLinkedQueueTail
tail
Fields inherited from class org.agrona.concurrent.ManyToOneConcurrentLinkedQueuePadding1
HEAD_OFFSET, NEXT_OFFSET, p000, p001, p002, p003, p004, p005, p006, p007, p008, p009, p010, p011, p012, p013, p014, p015, p016, p017, p018, p019, p020, p021, p022, p023, p024, p025, p026, p027, p028, p029, p030, p031, p032, p033, p034, p035, p036, p037, p038, p039, p040, p041, p042, p043, p044, p045, p046, p047, p048, p049, p050, p051, p052, p053, p054, p055, p056, p057, p058, p059, p060, p061, p062, p063, TAIL_OFFSET
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionboolean
boolean
addAll
(Collection<? extends E> c) private boolean
casTail
(ManyToOneConcurrentLinkedQueuePadding1.Node<E> expectedNode, ManyToOneConcurrentLinkedQueuePadding1.Node<E> updateNode) void
clear()
boolean
boolean
containsAll
(Collection<?> c) element()
private void
boolean
isEmpty()
iterator()
boolean
peek()
poll()
remove()
boolean
boolean
removeAll
(Collection<?> c) boolean
retainAll
(Collection<?> c) int
size()
Size can be considered an approximation on a moving list.Object[]
toArray()
<T> T[]
toArray
(T[] a) toString()
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.util.Collection
equals, hashCode, parallelStream, removeIf, spliterator, stream, toArray
-
Field Details
-
p128
byte p128 -
p129
byte p129 -
p130
byte p130 -
p131
byte p131 -
p132
byte p132 -
p133
byte p133 -
p134
byte p134 -
p135
byte p135 -
p136
byte p136 -
p137
byte p137 -
p138
byte p138 -
p139
byte p139 -
p140
byte p140 -
p142
byte p142 -
p143
byte p143 -
p144
byte p144 -
p145
byte p145 -
p146
byte p146 -
p147
byte p147 -
p148
byte p148 -
p149
byte p149 -
p150
byte p150 -
p151
byte p151 -
p152
byte p152 -
p153
byte p153 -
p154
byte p154 -
p155
byte p155 -
p156
byte p156 -
p157
byte p157 -
p158
byte p158 -
p159
byte p159 -
p160
byte p160 -
p161
byte p161 -
p162
byte p162 -
p163
byte p163 -
p164
byte p164 -
p165
byte p165 -
p166
byte p166 -
p167
byte p167 -
p168
byte p168 -
p169
byte p169 -
p170
byte p170 -
p171
byte p171 -
p172
byte p172 -
p173
byte p173 -
p174
byte p174 -
p175
byte p175 -
p176
byte p176 -
p177
byte p177 -
p178
byte p178 -
p179
byte p179 -
p180
byte p180 -
p181
byte p181 -
p182
byte p182 -
p183
byte p183 -
p184
byte p184 -
p185
byte p185 -
p186
byte p186 -
p187
byte p187 -
p189
byte p189 -
p190
byte p190 -
p191
byte p191 -
p192
byte p192 -
p193
byte p193 -
empty
-
-
Constructor Details
-
ManyToOneConcurrentLinkedQueue
public ManyToOneConcurrentLinkedQueue()Constructs an empty queue.
-
-
Method Details
-
add
-
offer
-
remove
-
poll
-
element
-
peek
-
size
public int size()Size can be considered an approximation on a moving list. It is only really stable when the consumer is inactive. If you want to check forqueue.size() == 0
thenisEmpty()
is a better alternative.This operation is O(n) on the length of the linked chain.
- Specified by:
size
in interfaceCollection<E>
- Returns:
- an approximation for the size of the list.
-
isEmpty
public boolean isEmpty()- Specified by:
isEmpty
in interfaceCollection<E>
-
contains
- Specified by:
contains
in interfaceCollection<E>
-
iterator
-
toArray
- Specified by:
toArray
in interfaceCollection<E>
-
toArray
public <T> T[] toArray(T[] a) - Specified by:
toArray
in interfaceCollection<E>
-
remove
- Specified by:
remove
in interfaceCollection<E>
-
containsAll
- Specified by:
containsAll
in interfaceCollection<E>
-
addAll
- Specified by:
addAll
in interfaceCollection<E>
-
removeAll
- Specified by:
removeAll
in interfaceCollection<E>
-
retainAll
- Specified by:
retainAll
in interfaceCollection<E>
-
clear
public void clear()- Specified by:
clear
in interfaceCollection<E>
-
toString
-
headOrdered
-
swapTail
private ManyToOneConcurrentLinkedQueuePadding1.Node<E> swapTail(ManyToOneConcurrentLinkedQueuePadding1.Node<E> newTail) -
casTail
private boolean casTail(ManyToOneConcurrentLinkedQueuePadding1.Node<E> expectedNode, ManyToOneConcurrentLinkedQueuePadding1.Node<E> updateNode)
-