Class MemorySafeLinkedBlockingQueue<E>
- java.lang.Object
-
- java.util.AbstractCollection<E>
-
- java.util.AbstractQueue<E>
-
- java.util.concurrent.LinkedBlockingQueue<E>
-
- org.apache.shenyu.common.concurrent.MemorySafeLinkedBlockingQueue<E>
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Iterable<E>,java.util.Collection<E>,java.util.concurrent.BlockingQueue<E>,java.util.Queue<E>
- Direct Known Subclasses:
MemorySafeTaskQueue
public class MemorySafeLinkedBlockingQueue<E> extends java.util.concurrent.LinkedBlockingQueue<E>Can completely solve the OOM problem caused byLinkedBlockingQueue, does not depend onInstrumentationand is easier to use thanMemoryLimitedLinkedBlockingQueue.- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description MemorySafeLinkedBlockingQueue(int maxFreeMemory)MemorySafeLinkedBlockingQueue(java.util.Collection<? extends E> c, int maxFreeMemory)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intgetMaxFreeMemory()get the max free memory.booleanhasRemainedMemory()determine if there is any remaining free memory.booleanoffer(E e)booleanoffer(E e, long timeout, java.util.concurrent.TimeUnit unit)voidput(E e)voidsetMaxFreeMemory(int maxFreeMemory)set the max free memory.voidsetRejector(Rejector<E> rejector)set the rejector.-
Methods inherited from class java.util.concurrent.LinkedBlockingQueue
clear, contains, drainTo, drainTo, forEach, iterator, peek, poll, poll, remainingCapacity, remove, removeAll, removeIf, retainAll, size, spliterator, take, toArray, toArray, toString
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
-
-
-
Constructor Detail
-
MemorySafeLinkedBlockingQueue
public MemorySafeLinkedBlockingQueue(int maxFreeMemory)
-
MemorySafeLinkedBlockingQueue
public MemorySafeLinkedBlockingQueue(java.util.Collection<? extends E> c, int maxFreeMemory)
-
-
Method Detail
-
setMaxFreeMemory
public void setMaxFreeMemory(int maxFreeMemory)
set the max free memory.- Parameters:
maxFreeMemory- the max free memory
-
getMaxFreeMemory
public int getMaxFreeMemory()
get the max free memory.- Returns:
- the max free memory limit
-
setRejector
public void setRejector(Rejector<E> rejector)
set the rejector.- Parameters:
rejector- the rejector
-
hasRemainedMemory
public boolean hasRemainedMemory()
determine if there is any remaining free memory.- Returns:
- true if has free memory
-
put
public void put(E e) throws java.lang.InterruptedException
-
offer
public boolean offer(E e, long timeout, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedException
-
-