Class MemoryLimiter

    • Constructor Summary

      Constructors 
      Constructor Description
      MemoryLimiter​(long memoryLimit, java.lang.instrument.Instrumentation inst)  
      MemoryLimiter​(java.lang.instrument.Instrumentation inst)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean acquire​(java.lang.Object o)
      acquire memory by Object.
      boolean acquire​(java.lang.Object o, long timeout, java.util.concurrent.TimeUnit unit)
      acquire memory by Object.
      void acquireInterruptibly​(java.lang.Object o)
      acquire memory by Object.
      long getCurrentMemory()
      get the current memory.
      long getCurrentRemainMemory()
      get the current remain memory.
      long getMemoryLimit()
      get the memory limit.
      void release​(java.lang.Object o)
      release memory by Object.
      void releaseInterruptibly​(java.lang.Object o)
      release memory by Object.
      void releaseInterruptibly​(java.lang.Object o, long timeout, java.util.concurrent.TimeUnit unit)
      release memory by Object.
      void reset()
      reset this MemoryLimiter.
      void setMemoryLimit​(long memoryLimit)
      set the memory limit.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • MemoryLimiter

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

        public MemoryLimiter​(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
      • acquire

        public boolean acquire​(java.lang.Object o)
        acquire memory by Object. this method does not respond to interrupts.
        Parameters:
        o - memory size to be applied by calculating
        Returns:
        true if acquire success
      • acquire

        public boolean acquire​(java.lang.Object o,
                               long timeout,
                               java.util.concurrent.TimeUnit unit)
                        throws java.lang.InterruptedException
        acquire memory by Object. this method response to interrupts.
        Parameters:
        o - memory size to be applied by calculating
        timeout - max time to wait
        unit - time unit
        Returns:
        true if acquire success
        Throws:
        java.lang.InterruptedException - the InterruptedException
      • acquireInterruptibly

        public void acquireInterruptibly​(java.lang.Object o)
                                  throws java.lang.InterruptedException
        acquire memory by Object. this method response to interrupts.
        Parameters:
        o - memory size to be applied by calculating
        Throws:
        java.lang.InterruptedException - the InterruptedException
      • release

        public void release​(java.lang.Object o)
        release memory by Object. this method does not respond to interrupts.
        Parameters:
        o - memory size to be applied by calculating
      • releaseInterruptibly

        public void releaseInterruptibly​(java.lang.Object o)
                                  throws java.lang.InterruptedException
        release memory by Object. this method response to interrupts.
        Parameters:
        o - memory size to be applied by calculating
        Throws:
        java.lang.InterruptedException - the InterruptedException
      • releaseInterruptibly

        public void releaseInterruptibly​(java.lang.Object o,
                                         long timeout,
                                         java.util.concurrent.TimeUnit unit)
                                  throws java.lang.InterruptedException
        release memory by Object. this method response to interrupts.
        Parameters:
        o - memory size to be applied by calculating
        timeout - max time to wait
        unit - time unit
        Throws:
        java.lang.InterruptedException - the InterruptedException
      • reset

        public void reset()
        reset this MemoryLimiter.