Class FailSafeTimer


  • public class FailSafeTimer
    extends java.lang.Object
    A fail-safe timer in the sense that if the runtime environment restricts creating new threads, it doesn't blow up with an exception. TimerTasks that are scheduled will run at least once (inline when they are scheduled) if creating threads is not allowed. For example, Google App Engine does not allow creation of new threads.

    Clients should not use this as a general purpose timing service. To do so could interfere with the running of the Cache.

    Since:
    1.7
    Author:
    Abhishek Sanoujam
    • Constructor Summary

      Constructors 
      Constructor Description
      FailSafeTimer​(java.lang.String name)
      Constructor accepting a name for the timer.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void cancel()
      If the runtime environment restricts thread creation, this method does nothing.
      int purge()
      If the runtime environment restricts thread creation, this method does nothing.
      void schedule​(java.util.TimerTask task, long delay)
      If the runtime environment restricts thread creation, the task is run inline for only one time.
      void schedule​(java.util.TimerTask task, long delay, long period)
      If the runtime environment restricts thread creation, the task is run inline for only one time.
      void schedule​(java.util.TimerTask task, java.util.Date time)
      If the runtime environment restricts thread creation, the task is run inline for only one time.
      void schedule​(java.util.TimerTask task, java.util.Date firstTime, long period)
      If the runtime environment restricts thread creation, the task is run inline for only one time.
      void scheduleAtFixedRate​(java.util.TimerTask task, long delay, long period)
      If the runtime environment restricts thread creation, the task is run inline for only one time.
      void scheduleAtFixedRate​(java.util.TimerTask task, java.util.Date firstTime, long period)
      If the runtime environment restricts thread creation, the task is run inline for only one time.
      • Methods inherited from class java.lang.Object

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

      • FailSafeTimer

        public FailSafeTimer​(java.lang.String name)
        Constructor accepting a name for the timer. The scheduling thread is created as a daemon
        Parameters:
        name -
    • Method Detail

      • cancel

        public void cancel()
        If the runtime environment restricts thread creation, this method does nothing.
        See Also:
        Timer.cancel()
      • purge

        public int purge()
        If the runtime environment restricts thread creation, this method does nothing.
        See Also:
        Timer.purge()
      • schedule

        public void schedule​(java.util.TimerTask task,
                             java.util.Date firstTime,
                             long period)
        If the runtime environment restricts thread creation, the task is run inline for only one time. No further repeated execution happens for the task
        See Also:
        Timer.schedule(java.util.TimerTask, java.util.Date, long)
      • schedule

        public void schedule​(java.util.TimerTask task,
                             java.util.Date time)
        If the runtime environment restricts thread creation, the task is run inline for only one time. No further repeated execution happens for the task
        See Also:
        Timer.schedule(java.util.TimerTask, java.util.Date)
      • schedule

        public void schedule​(java.util.TimerTask task,
                             long delay,
                             long period)
        If the runtime environment restricts thread creation, the task is run inline for only one time. No further repeated execution happens for the task
        See Also:
        Timer.schedule(java.util.TimerTask, long, long)
      • schedule

        public void schedule​(java.util.TimerTask task,
                             long delay)
        If the runtime environment restricts thread creation, the task is run inline for only one time. No further repeated execution happens for the task
        See Also:
        Timer.schedule(java.util.TimerTask, long)
      • scheduleAtFixedRate

        public void scheduleAtFixedRate​(java.util.TimerTask task,
                                        java.util.Date firstTime,
                                        long period)
        If the runtime environment restricts thread creation, the task is run inline for only one time. No further repeated execution happens for the task
        See Also:
        Timer.scheduleAtFixedRate(java.util.TimerTask, java.util.Date, long)
      • scheduleAtFixedRate

        public void scheduleAtFixedRate​(java.util.TimerTask task,
                                        long delay,
                                        long period)
        If the runtime environment restricts thread creation, the task is run inline for only one time. No further repeated execution happens for the task
        See Also:
        Timer.scheduleAtFixedRate(java.util.TimerTask, long, long)