Class PoolUtils.ErodingFactor

java.lang.Object
org.apache.commons.pool.PoolUtils.ErodingFactor
Enclosing class:
PoolUtils

private static class PoolUtils.ErodingFactor extends 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 final float
    Determines frequency of "erosion" events
    private int
    High water mark - largest numIdle encountered
    private long
    Time of next shrink event
  • Constructor Summary

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

    Modifier and Type
    Method
    Description
    long
    Returns the time of the next erosion event.
    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 Details

    • 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 Details

    • ErodingFactor

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

    • 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 String toString()
      Overrides:
      toString in class Object