Package org.jgroups.util
Class ConcurrentLinkedBlockingQueue<T>
- java.lang.Object
-
- java.util.AbstractCollection<E>
-
- java.util.AbstractQueue<E>
-
- java.util.concurrent.ConcurrentLinkedQueue<T>
-
- org.jgroups.util.ConcurrentLinkedBlockingQueue<T>
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Iterable<T>,java.util.Collection<T>,java.util.concurrent.BlockingQueue<T>,java.util.Queue<T>
public class ConcurrentLinkedBlockingQueue<T> extends java.util.concurrent.ConcurrentLinkedQueue<T> implements java.util.concurrent.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:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description private intcapacityprivate java.util.concurrent.locks.Locklockprivate java.util.concurrent.locks.Conditionnot_emptyprivate static longserialVersionUIDprivate java.util.concurrent.atomic.AtomicIntegerwaiting_takers
-
Constructor Summary
Constructors Constructor Description ConcurrentLinkedBlockingQueue(int capacity)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intdrainTo(java.util.Collection<? super T> c)intdrainTo(java.util.Collection<? super T> c, int maxElements)booleanoffer(T t)Drops elements if capacity has been reached.booleanoffer(T t, long timeout, java.util.concurrent.TimeUnit unit)Tpoll()Tpoll(long timeout, java.util.concurrent.TimeUnit unit)voidput(T t)intremainingCapacity()booleanremove(java.lang.Object o)Ttake()-
Methods inherited from class java.util.concurrent.ConcurrentLinkedQueue
add, addAll, clear, contains, forEach, isEmpty, iterator, peek, removeAll, removeIf, retainAll, size, spliterator, toArray, toArray, toString
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
capacity
private final int capacity
-
lock
private final java.util.concurrent.locks.Lock lock
-
not_empty
private final java.util.concurrent.locks.Condition not_empty
-
waiting_takers
private final java.util.concurrent.atomic.AtomicInteger waiting_takers
-
-
Method Detail
-
offer
public boolean offer(T t)
Drops elements if capacity has been reached. That's OK for the ThreadPoolExecutor as dropped messages will get retransmitted
-
take
public T take() throws java.lang.InterruptedException
- Specified by:
takein interfacejava.util.concurrent.BlockingQueue<T>- Throws:
java.lang.InterruptedException
-
poll
public T poll()
-
poll
public T poll(long timeout, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedException
- Specified by:
pollin interfacejava.util.concurrent.BlockingQueue<T>- Throws:
java.lang.InterruptedException
-
remove
public boolean remove(java.lang.Object o)
-
remainingCapacity
public int remainingCapacity()
- Specified by:
remainingCapacityin interfacejava.util.concurrent.BlockingQueue<T>
-
drainTo
public int drainTo(java.util.Collection<? super T> c)
- Specified by:
drainToin interfacejava.util.concurrent.BlockingQueue<T>
-
put
public void put(T t) throws java.lang.InterruptedException
- Specified by:
putin interfacejava.util.concurrent.BlockingQueue<T>- Throws:
java.lang.InterruptedException
-
offer
public boolean offer(T t, long timeout, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedException
- Specified by:
offerin interfacejava.util.concurrent.BlockingQueue<T>- Throws:
java.lang.InterruptedException
-
-