Package org.jgroups.util
Class ConcurrentLinkedBlockingQueue<T>
java.lang.Object
java.util.AbstractCollection<T>
java.util.AbstractQueue<T>
java.util.concurrent.ConcurrentLinkedQueue<T>
org.jgroups.util.ConcurrentLinkedBlockingQueue<T>
- All Implemented Interfaces:
Serializable,Iterable<T>,Collection<T>,BlockingQueue<T>,Queue<T>
public class ConcurrentLinkedBlockingQueue<T>
extends ConcurrentLinkedQueue<T>
implements BlockingQueue<T>
Attempt at writing a fast transfer queue, which is bounded. The take() method blocks until there is an element, but
the offer() method drops the element and returns if the queue is full (doesn't block). I thought this class would
be useful in ThreadPoolExecutor, as a replacement for LinkedBlockingQueue, but the perf didn't change. I'll keep it
for later reference ...
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final intprivate final Lockprivate final Conditionprivate static final longprivate final AtomicInteger -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintdrainTo(Collection<? super T> c) intdrainTo(Collection<? super T> c, int maxElements) booleanDrops elements if capacity has been reached.booleanpoll()voidintbooleantake()Methods inherited from class java.util.concurrent.ConcurrentLinkedQueue
add, addAll, clear, contains, forEach, isEmpty, iterator, peek, removeAll, removeIf, retainAll, size, spliterator, toArray, toArray, toStringMethods inherited from class java.util.AbstractQueue
element, removeMethods inherited from class java.util.AbstractCollection
containsAllMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.concurrent.BlockingQueue
add, containsMethods inherited from interface java.util.Collection
addAll, clear, containsAll, equals, hashCode, isEmpty, iterator, parallelStream, removeAll, removeIf, retainAll, size, spliterator, stream, toArray, toArray, toArray
-
Field Details
-
serialVersionUID
private static final long serialVersionUID- See Also:
-
capacity
private final int capacity -
lock
-
not_empty
-
waiting_takers
-
-
Constructor Details
-
ConcurrentLinkedBlockingQueue
public ConcurrentLinkedBlockingQueue(int capacity)
-
-
Method Details
-
offer
Drops elements if capacity has been reached. That's OK for the ThreadPoolExecutor as dropped messages will get retransmitted- Specified by:
offerin interfaceBlockingQueue<T>- Specified by:
offerin interfaceQueue<T>- Overrides:
offerin classConcurrentLinkedQueue<T>- Parameters:
t-- Returns:
-
take
- Specified by:
takein interfaceBlockingQueue<T>- Throws:
InterruptedException
-
poll
-
poll
- Specified by:
pollin interfaceBlockingQueue<T>- Throws:
InterruptedException
-
remove
- Specified by:
removein interfaceBlockingQueue<T>- Specified by:
removein interfaceCollection<T>- Overrides:
removein classConcurrentLinkedQueue<T>
-
remainingCapacity
public int remainingCapacity()- Specified by:
remainingCapacityin interfaceBlockingQueue<T>
-
drainTo
- Specified by:
drainToin interfaceBlockingQueue<T>
-
put
- Specified by:
putin interfaceBlockingQueue<T>- Throws:
InterruptedException
-
offer
- Specified by:
offerin interfaceBlockingQueue<T>- Throws:
InterruptedException
-
drainTo
- Specified by:
drainToin interfaceBlockingQueue<T>
-