Class PoolUtils.ErodingFactor

  • Enclosing class:
    PoolUtils

    private static class PoolUtils.ErodingFactor
    extends java.lang.Object
    Encapsulate the logic for when the next poolable object should be discarded. Each time update is called, the next time to shrink is recomputed, based on the float factor, number of idle instances in the pool and high water mark. Float factor is assumed to be between 0 and 1. Values closer to 1 cause less frequent erosion events. Erosion event timing also depends on numIdle. When this value is relatively high (close to previously established high water mark), erosion occurs more frequently.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private float factor
      Determines frequency of "erosion" events
      private int idleHighWaterMark
      High water mark - largest numIdle encountered
      private long nextShrink
      Time of next shrink event
    • Constructor Summary

      Constructors 
      Constructor Description
      ErodingFactor​(float factor)
      Create a new ErodingFactor with the given erosion factor.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      long getNextShrink()
      Returns the time of the next erosion event.
      java.lang.String toString()
      void update​(int numIdle)
      Updates internal state based on numIdle and the current time.
      void update​(long now, int numIdle)
      Updates internal state using the supplied time and numIdle.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • factor

        private final float factor
        Determines frequency of "erosion" events
      • nextShrink

        private transient volatile long nextShrink
        Time of next shrink event
      • idleHighWaterMark

        private transient volatile int idleHighWaterMark
        High water mark - largest numIdle encountered
    • Constructor Detail

      • ErodingFactor

        public ErodingFactor​(float factor)
        Create a new ErodingFactor with the given erosion factor.
        Parameters:
        factor - erosion factor
    • Method Detail

      • update

        public void update​(int numIdle)
        Updates internal state based on numIdle and the current time.
        Parameters:
        numIdle - number of idle elements in the pool
      • update

        public void update​(long now,
                           int numIdle)
        Updates internal state using the supplied time and numIdle.
        Parameters:
        now - current time
        numIdle - number of idle elements in the pool
      • getNextShrink

        public long getNextShrink()
        Returns the time of the next erosion event.
        Returns:
        next shrink time
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object