Class ScheduledExecutorUtil


  • public class ScheduledExecutorUtil
    extends java.lang.Object
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.RuntimeException propagate​(java.lang.Throwable throwable)  
      static java.util.concurrent.ScheduledFuture<?> safelyScheduleAtFixedRate​(java.util.concurrent.ScheduledExecutorService executor, java.lang.Runnable command, long initialDelay, long period, java.util.concurrent.TimeUnit unit)
      A safe wrapper method to make sure the exception thrown by the previous running will not affect the next one.
      static java.util.concurrent.ScheduledFuture<?> safelyScheduleWithFixedDelay​(java.util.concurrent.ScheduledExecutorService executor, java.lang.Runnable command, long initialDelay, long delay, java.util.concurrent.TimeUnit unit)
      A safe wrapper method to make sure the exception thrown by the previous running will not affect the next one.
      static java.util.concurrent.ScheduledFuture<?> unsafelyScheduleAtFixedRate​(java.util.concurrent.ScheduledExecutorService executor, java.lang.Runnable command, long initialDelay, long period, java.util.concurrent.TimeUnit unit)
      A wrapper method to have the same semantic with ScheduledExecutorService.scheduleAtFixedRate(Runnable, long, long, TimeUnit), except for logging an error log when any uncaught exception happens.
      static java.util.concurrent.ScheduledFuture<?> unsafelyScheduleWithFixedDelay​(java.util.concurrent.ScheduledExecutorService executor, java.lang.Runnable command, long initialDelay, long delay, java.util.concurrent.TimeUnit unit)
      A wrapper method to have the same semantic with ScheduledExecutorService.scheduleWithFixedDelay(Runnable, long, long, TimeUnit), except for logging an error log when any uncaught exception happens.
      • Methods inherited from class java.lang.Object

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

      • ScheduledExecutorUtil

        public ScheduledExecutorUtil()
    • Method Detail

      • safelyScheduleAtFixedRate

        public static java.util.concurrent.ScheduledFuture<?> safelyScheduleAtFixedRate​(java.util.concurrent.ScheduledExecutorService executor,
                                                                                        java.lang.Runnable command,
                                                                                        long initialDelay,
                                                                                        long period,
                                                                                        java.util.concurrent.TimeUnit unit)
        A safe wrapper method to make sure the exception thrown by the previous running will not affect the next one. Please reference the javadoc of ScheduledExecutorService.scheduleAtFixedRate(Runnable, long, long, TimeUnit) for more details.
        Parameters:
        executor - the ScheduledExecutorService instance.
        command - same parameter in ScheduledExecutorService.scheduleAtFixedRate(Runnable, long, long, TimeUnit).
        initialDelay - same parameter in ScheduledExecutorService.scheduleAtFixedRate(Runnable, long, long, TimeUnit).
        period - same parameter in ScheduledExecutorService.scheduleAtFixedRate(Runnable, long, long, TimeUnit).
        unit - same parameter in ScheduledExecutorService.scheduleAtFixedRate(Runnable, long, long, TimeUnit).
        Returns:
        the same return value of ScheduledExecutorService.scheduleAtFixedRate(Runnable, long, long, TimeUnit).
      • safelyScheduleWithFixedDelay

        public static java.util.concurrent.ScheduledFuture<?> safelyScheduleWithFixedDelay​(java.util.concurrent.ScheduledExecutorService executor,
                                                                                           java.lang.Runnable command,
                                                                                           long initialDelay,
                                                                                           long delay,
                                                                                           java.util.concurrent.TimeUnit unit)
        A safe wrapper method to make sure the exception thrown by the previous running will not affect the next one. Please reference the javadoc of ScheduledExecutorService.scheduleWithFixedDelay(Runnable, long, long, TimeUnit) for more details.
        Parameters:
        executor - the ScheduledExecutorService instance.
        command - same parameter in ScheduledExecutorService.scheduleWithFixedDelay(Runnable, long, long, TimeUnit).
        initialDelay - same parameter in ScheduledExecutorService.scheduleWithFixedDelay(Runnable, long, long, TimeUnit).
        delay - same parameter in ScheduledExecutorService.scheduleWithFixedDelay(Runnable, long, long, TimeUnit).
        unit - same parameter in ScheduledExecutorService.scheduleWithFixedDelay(Runnable, long, long, TimeUnit).
        Returns:
        the same return value of ScheduledExecutorService.scheduleWithFixedDelay(Runnable, long, long, TimeUnit).
      • unsafelyScheduleAtFixedRate

        public static java.util.concurrent.ScheduledFuture<?> unsafelyScheduleAtFixedRate​(java.util.concurrent.ScheduledExecutorService executor,
                                                                                          java.lang.Runnable command,
                                                                                          long initialDelay,
                                                                                          long period,
                                                                                          java.util.concurrent.TimeUnit unit)
        A wrapper method to have the same semantic with ScheduledExecutorService.scheduleAtFixedRate(Runnable, long, long, TimeUnit), except for logging an error log when any uncaught exception happens.
        Parameters:
        executor - the ScheduledExecutorService instance.
        command - same parameter in ScheduledExecutorService.scheduleAtFixedRate(Runnable, long, long, TimeUnit).
        initialDelay - same parameter in ScheduledExecutorService.scheduleAtFixedRate(Runnable, long, long, TimeUnit).
        period - same parameter in ScheduledExecutorService.scheduleAtFixedRate(Runnable, long, long, TimeUnit).
        unit - same parameter in ScheduledExecutorService.scheduleAtFixedRate(Runnable, long, long, TimeUnit).
        Returns:
        the same return value of ScheduledExecutorService.scheduleAtFixedRate(Runnable, long, long, TimeUnit).
      • unsafelyScheduleWithFixedDelay

        public static java.util.concurrent.ScheduledFuture<?> unsafelyScheduleWithFixedDelay​(java.util.concurrent.ScheduledExecutorService executor,
                                                                                             java.lang.Runnable command,
                                                                                             long initialDelay,
                                                                                             long delay,
                                                                                             java.util.concurrent.TimeUnit unit)
        A wrapper method to have the same semantic with ScheduledExecutorService.scheduleWithFixedDelay(Runnable, long, long, TimeUnit), except for logging an error log when any uncaught exception happens.
        Parameters:
        executor - the ScheduledExecutorService instance.
        command - same parameter in ScheduledExecutorService.scheduleWithFixedDelay(Runnable, long, long, TimeUnit).
        initialDelay - same parameter in ScheduledExecutorService.scheduleWithFixedDelay(Runnable, long, long, TimeUnit).
        delay - same parameter in ScheduledExecutorService.scheduleWithFixedDelay(Runnable, long, long, TimeUnit).
        unit - same parameter in ScheduledExecutorService.scheduleWithFixedDelay(Runnable, long, long, TimeUnit).
        Returns:
        the same return value of ScheduledExecutorService.scheduleWithFixedDelay(Runnable, long, long, TimeUnit).
      • propagate

        public static java.lang.RuntimeException propagate​(java.lang.Throwable throwable)