Class SingletonTimerFactory

  • All Implemented Interfaces:
    ModuleControl, TimerFactory

    public class SingletonTimerFactory
    extends java.lang.Object
    implements TimerFactory, ModuleControl
    This class implements the TimerFactory interface. It creates a singleton Timer instance. The class implements the ModuleControl interface, because it needs to cancel the Timer at system shutdown.
    See Also:
    TimerFactory, ModuleControl
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.concurrent.atomic.AtomicInteger cancelCount
      The number of times cancel(TimerTask) has been called.
      private java.util.Timer singletonTimer
      Singleton Timer instance.
      private java.lang.StringBuilder warnings
      Initialization warnings.
    • Constructor Summary

      Constructors 
      Constructor Description
      SingletonTimerFactory()
      Initializes this TimerFactory with a singleton Timer instance.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void boot​(boolean create, java.util.Properties properties)
      Currently does nothing, singleton Timer instance is initialized in the constructor.
      void cancel​(java.util.TimerTask task)
      Cancel a task.
      private java.lang.ClassLoader getContextClassLoader()
      Check if the current context class loader could cause a memory leak (DERBY-3745) if it is inherited by the timer thread, and return it if that is the case.
      java.lang.String getWarnings()
      Return any warnings generated during the initialization of this class, or null if none
      private void report​(java.lang.SecurityException se, java.lang.String id)  
      void schedule​(java.util.TimerTask task, long delay)
      Schedule a task.
      private void setContextClassLoader​(java.lang.ClassLoader cl)  
      void stop()
      Cancels the singleton Timer instance.
      • Methods inherited from class java.lang.Object

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

      • singletonTimer

        private final java.util.Timer singletonTimer
        Singleton Timer instance.
      • cancelCount

        private final java.util.concurrent.atomic.AtomicInteger cancelCount
        The number of times cancel(TimerTask) has been called. Used for determining whether it's time to purge cancelled tasks from the timer.
      • warnings

        private java.lang.StringBuilder warnings
        Initialization warnings. See getWarnings().
    • Constructor Detail

      • SingletonTimerFactory

        public SingletonTimerFactory()
        Initializes this TimerFactory with a singleton Timer instance.
    • Method Detail

      • schedule

        public void schedule​(java.util.TimerTask task,
                             long delay)
        Description copied from interface: TimerFactory
        Schedule a task.
        Specified by:
        schedule in interface TimerFactory
        Parameters:
        task - the task to schedule
        delay - how many milliseconds to wait before executing the task
      • cancel

        public void cancel​(java.util.TimerTask task)
        Description copied from interface: TimerFactory
        Cancel a task.
        Specified by:
        cancel in interface TimerFactory
        Parameters:
        task - the task to cancel
      • boot

        public void boot​(boolean create,
                         java.util.Properties properties)
                  throws StandardException
        Currently does nothing, singleton Timer instance is initialized in the constructor. Implements the ModuleControl interface.
        Specified by:
        boot in interface ModuleControl
        Parameters:
        create - not used
        properties - not used
        Throws:
        StandardException - not used
        See Also:
        ModuleControl
      • stop

        public void stop()
        Cancels the singleton Timer instance. Implements the ModuleControl interface.
        Specified by:
        stop in interface ModuleControl
        See Also:
        ModuleControl
      • getContextClassLoader

        private java.lang.ClassLoader getContextClassLoader()
        Check if the current context class loader could cause a memory leak (DERBY-3745) if it is inherited by the timer thread, and return it if that is the case.
        Returns:
        the context class loader of the current thread if it is not the same class loader as the one used by the system classes or the Derby classes and we have permission to read the class loaders, or null otherwise
      • setContextClassLoader

        private void setContextClassLoader​(java.lang.ClassLoader cl)
      • report

        private void report​(java.lang.SecurityException se,
                            java.lang.String id)
      • getWarnings

        public java.lang.String getWarnings()
        Return any warnings generated during the initialization of this class, or null if none
        Returns:
        See legend