Package net.i2p.util

Class SimpleTimer2

  • Direct Known Subclasses:
    RetransmissionTimer

    public class SimpleTimer2
    extends Object
    Simple event scheduler - toss an event on the queue and it gets fired at the appropriate time. The method that is fired however should NOT block (otherwise they b0rk the timer). This rewrites the old SimpleTimer to use the java.util.concurrent.ScheduledThreadPoolExecutor. SimpleTimer has problems with lock contention; this should work a lot better. This supports cancelling and arbitrary rescheduling. If you don't need that, use SimpleScheduler instead. SimpleTimer is deprecated, use this or SimpleScheduler.
    Author:
    zzz
    • Constructor Detail

      • SimpleTimer2

        public SimpleTimer2​(I2PAppContext context)
        To be instantiated by the context. Others should use context.simpleTimer2() instead
      • SimpleTimer2

        protected SimpleTimer2​(I2PAppContext context,
                               String name)
        To be instantiated by the context. Others should use context.simpleTimer2() instead
      • SimpleTimer2

        protected SimpleTimer2​(I2PAppContext context,
                               String name,
                               boolean prestartAllThreads)
        To be instantiated by the context. Others should use context.simpleTimer2() instead
        Since:
        0.9
    • Method Detail

      • getInstance

        public static SimpleTimer2 getInstance()
        If you have a context, use context.simpleTimer2() instead
      • stop

        public void stop()
        Stops the SimpleTimer. Subsequent executions should not throw a RejectedExecutionException. Cannot be restarted.
      • addEvent

        public void addEvent​(SimpleTimer.TimedEvent event,
                             long timeoutMs)
        Queue up the given event to be fired no sooner than timeoutMs from now. For transition from SimpleScheduler. Uncancellable. New code should use SimpleTimer2.TimedEvent.
        Parameters:
        event - to be run once
        timeoutMs - run after this delay
        Since:
        0.9.20
      • addPeriodicEvent

        public void addPeriodicEvent​(SimpleTimer.TimedEvent event,
                                     long timeoutMs)
        Schedule periodic event The TimedEvent must not do its own rescheduling. As all Exceptions are caught in run(), these will not prevent subsequent executions (unlike SimpleTimer, where the TimedEvent does its own rescheduling). For transition from SimpleScheduler. Uncancellable. New code should use SimpleTimer2.TimedEvent.
        Parameters:
        timeoutMs - run subsequent iterations of this event every timeoutMs ms, 5000 minimum
        Throws:
        IllegalArgumentException - if timeoutMs less than 5000
        Since:
        0.9.20
      • addPeriodicEvent

        public void addPeriodicEvent​(SimpleTimer.TimedEvent event,
                                     long delay,
                                     long timeoutMs)
        Schedule periodic event The TimedEvent must not do its own rescheduling. As all Exceptions are caught in run(), these will not prevent subsequent executions (unlike SimpleTimer, where the TimedEvent does its own rescheduling). For transition from SimpleScheduler. Uncancellable. New code should use SimpleTimer2.TimedEvent.
        Parameters:
        delay - run the first iteration of this event after delay ms
        timeoutMs - run subsequent iterations of this event every timeoutMs ms, 5000 minimum
        Throws:
        IllegalArgumentException - if timeoutMs less than 5000
        Since:
        0.9.20