Class EvictionTimer


  • final class EvictionTimer
    extends java.lang.Object
    Provides a shared idle object eviction timer for all pools.

    This class is currently implemented using ScheduledThreadPoolExecutor. This implementation may change in any future release. This class keeps track of how many pools are using it. If no pools are using the timer, it is canceled. This prevents a thread being left running which, in application server environments, can lead to memory leads and/or prevent applications from shutting down or reloading cleanly.

    This class has package scope to prevent its inclusion in the pool public API. The class declaration below should *not* be changed to public.

    This class is intended to be thread-safe.

    Since:
    2.0
    • Constructor Detail

      • EvictionTimer

        private EvictionTimer()
        Prevents instantiation
    • Method Detail

      • cancel

        static void cancel​(BaseGenericObjectPool.Evictor evictor,
                           java.time.Duration timeout,
                           boolean restarting)
        Removes the specified eviction task from the timer.
        Parameters:
        evictor - Task to be canceled.
        timeout - If the associated executor is no longer required, how long should this thread wait for the executor to terminate?
        restarting - The state of the evictor.
      • getExecutor

        static java.util.concurrent.ScheduledThreadPoolExecutor getExecutor()
        For testing only.
        Returns:
        The executor.
      • getNumTasks

        static int getNumTasks()
        Returns:
        the number of eviction tasks under management.
      • remove

        private static void remove​(BaseGenericObjectPool.Evictor evictor)
        Removes evictor from the task set and executor. Only called when holding the class lock.
        Parameters:
        evictor - Eviction task to remove
      • schedule

        static void schedule​(BaseGenericObjectPool.Evictor task,
                             java.time.Duration delay,
                             java.time.Duration period)
        Adds the specified eviction task to the timer. Tasks that are added with a call to this method *must* call cancel(BaseGenericObjectPool.Evictor, Duration, boolean) to cancel the task to prevent memory and/or thread leaks in application server environments.
        Parameters:
        task - Task to be scheduled.
        delay - Duration before task is executed.
        period - Duration between executions.
      • toString

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