Class MemoryLimitedLinkedBlockingQueue<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:
    MemoryLimitedTaskQueue

    public class MemoryLimitedLinkedBlockingQueue<E>
    extends java.util.concurrent.LinkedBlockingQueue<E>
    Can completely solve the OOM problem caused by LinkedBlockingQueue.
    See Also:
    MemoryLimiter, MemoryLimitCalculator, Serialized Form
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void clear()  
      long getCurrentMemory()
      get the current memory.
      long getCurrentRemainMemory()
      get the current remain memory.
      long getMemoryLimit()
      get the memory limit.
      boolean offer​(E e)  
      boolean offer​(E e, long timeout, java.util.concurrent.TimeUnit unit)  
      E poll()  
      E poll​(long timeout, java.util.concurrent.TimeUnit unit)  
      void put​(E e)  
      boolean remove​(java.lang.Object o)  
      void setMemoryLimit​(long memoryLimit)
      set the memory limit.
      E take()  
      • Methods inherited from class java.util.concurrent.LinkedBlockingQueue

        contains, drainTo, drainTo, forEach, iterator, peek, remainingCapacity, removeAll, removeIf, retainAll, size, spliterator, toArray, toArray, toString
      • Methods inherited from class java.util.AbstractQueue

        add, addAll, element, remove
      • Methods inherited from class java.util.AbstractCollection

        containsAll, isEmpty
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface java.util.concurrent.BlockingQueue

        add
      • Methods inherited from interface java.util.Collection

        addAll, containsAll, equals, hashCode, isEmpty, parallelStream, stream, toArray
      • Methods inherited from interface java.util.Queue

        element, remove
    • Constructor Detail

      • MemoryLimitedLinkedBlockingQueue

        public MemoryLimitedLinkedBlockingQueue​(java.lang.instrument.Instrumentation inst)
      • MemoryLimitedLinkedBlockingQueue

        public MemoryLimitedLinkedBlockingQueue​(long memoryLimit,
                                                java.lang.instrument.Instrumentation inst)
      • MemoryLimitedLinkedBlockingQueue

        public MemoryLimitedLinkedBlockingQueue​(java.util.Collection<? extends E> c,
                                                long memoryLimit,
                                                java.lang.instrument.Instrumentation inst)
    • Method Detail

      • setMemoryLimit

        public void setMemoryLimit​(long memoryLimit)
        set the memory limit.
        Parameters:
        memoryLimit - the memory limit
      • getMemoryLimit

        public long getMemoryLimit()
        get the memory limit.
        Returns:
        the memory limit
      • getCurrentMemory

        public long getCurrentMemory()
        get the current memory.
        Returns:
        the current memory
      • getCurrentRemainMemory

        public long getCurrentRemainMemory()
        get the current remain memory.
        Returns:
        the current remain memory
      • put

        public void put​(E e)
                 throws java.lang.InterruptedException
        Specified by:
        put in interface java.util.concurrent.BlockingQueue<E>
        Overrides:
        put in class java.util.concurrent.LinkedBlockingQueue<E>
        Throws:
        java.lang.InterruptedException
      • offer

        public boolean offer​(E e,
                             long timeout,
                             java.util.concurrent.TimeUnit unit)
                      throws java.lang.InterruptedException
        Specified by:
        offer in interface java.util.concurrent.BlockingQueue<E>
        Overrides:
        offer in class java.util.concurrent.LinkedBlockingQueue<E>
        Throws:
        java.lang.InterruptedException
      • offer

        public boolean offer​(E e)
        Specified by:
        offer in interface java.util.concurrent.BlockingQueue<E>
        Specified by:
        offer in interface java.util.Queue<E>
        Overrides:
        offer in class java.util.concurrent.LinkedBlockingQueue<E>
      • take

        public E take()
               throws java.lang.InterruptedException
        Specified by:
        take in interface java.util.concurrent.BlockingQueue<E>
        Overrides:
        take in class java.util.concurrent.LinkedBlockingQueue<E>
        Throws:
        java.lang.InterruptedException
      • poll

        public E poll​(long timeout,
                      java.util.concurrent.TimeUnit unit)
               throws java.lang.InterruptedException
        Specified by:
        poll in interface java.util.concurrent.BlockingQueue<E>
        Overrides:
        poll in class java.util.concurrent.LinkedBlockingQueue<E>
        Throws:
        java.lang.InterruptedException
      • poll

        public E poll()
        Specified by:
        poll in interface java.util.Queue<E>
        Overrides:
        poll in class java.util.concurrent.LinkedBlockingQueue<E>
      • remove

        public boolean remove​(java.lang.Object o)
        Specified by:
        remove in interface java.util.concurrent.BlockingQueue<E>
        Specified by:
        remove in interface java.util.Collection<E>
        Overrides:
        remove in class java.util.concurrent.LinkedBlockingQueue<E>
      • clear

        public void clear()
        Specified by:
        clear in interface java.util.Collection<E>
        Overrides:
        clear in class java.util.concurrent.LinkedBlockingQueue<E>