Class MemorySafeLinkedBlockingQueue<E>
java.lang.Object
java.util.AbstractCollection<E>
java.util.AbstractQueue<E>
java.util.concurrent.LinkedBlockingQueue<E>
org.apache.dubbo.common.threadpool.MemorySafeLinkedBlockingQueue<E>
- All Implemented Interfaces:
Serializable,Iterable<E>,Collection<E>,BlockingQueue<E>,Queue<E>
Can completely solve the OOM problem caused by
LinkedBlockingQueue,
does not depend on Instrumentation and is easier to use than
MemoryLimitedLinkedBlockingQueue.- See Also:
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionMemorySafeLinkedBlockingQueue(long maxFreeMemory) MemorySafeLinkedBlockingQueue(Collection<? extends E> c, int maxFreeMemory) -
Method Summary
Modifier and TypeMethodDescriptionlongget the max free memory.booleandetermine if there is any remaining free memory.booleanbooleanvoidvoidsetMaxFreeMemory(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, toStringMethods inherited from class java.util.AbstractQueue
add, addAll, element, removeMethods inherited from class java.util.AbstractCollection
containsAll, isEmptyMethods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.concurrent.BlockingQueue
addMethods inherited from interface java.util.Collection
addAll, containsAll, equals, hashCode, isEmpty, parallelStream, stream, toArray
-
Field Details
-
THE_256_MB
public static int THE_256_MB
-
-
Constructor Details
-
MemorySafeLinkedBlockingQueue
public MemorySafeLinkedBlockingQueue() -
MemorySafeLinkedBlockingQueue
public MemorySafeLinkedBlockingQueue(long maxFreeMemory) -
MemorySafeLinkedBlockingQueue
-
-
Method Details
-
setMaxFreeMemory
public void setMaxFreeMemory(int maxFreeMemory) set the max free memory.- Parameters:
maxFreeMemory- the max free memory
-
getMaxFreeMemory
public long getMaxFreeMemory()get the max free memory.- Returns:
- the max free memory limit
-
setRejector
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
- Specified by:
putin interfaceBlockingQueue<E>- Overrides:
putin classLinkedBlockingQueue<E>- Throws:
InterruptedException
-
offer
- Specified by:
offerin interfaceBlockingQueue<E>- Overrides:
offerin classLinkedBlockingQueue<E>- Throws:
InterruptedException
-
offer
- Specified by:
offerin interfaceBlockingQueue<E>- Specified by:
offerin interfaceQueue<E>- Overrides:
offerin classLinkedBlockingQueue<E>
-