Class ThreadUtils

java.lang.Object
io.github.syst3ms.skriptparser.util.ThreadUtils

public class ThreadUtils extends Object
  • Constructor Details

    • ThreadUtils

      public ThreadUtils()
  • Method Details

    • runAsync

      public static void runAsync(Runnable code)
      Run certain code once on a separate thread. The thread is shut down after the code ran.
      Parameters:
      code - the runnable that needs to be executed
    • runAfter

      public static void runAfter(Runnable code, Duration duration)
      Run certain code once after a certain delay. The thread is shut down after the code ran.
      Parameters:
      code - the runnable that needs to be executed
      duration - the delay
    • runPeriodically

      public static void runPeriodically(Runnable code, Duration duration)
      Runs certain code periodically.
      Parameters:
      code - the runnable that needs to be executed
      duration - the delay
    • runPeriodically

      public static void runPeriodically(Runnable code, Duration initialDelay, Duration duration)
      Runs certain code periodically.
      Parameters:
      code - the runnable that needs to be executed
      initialDelay - the initial delay
      duration - the delay
    • runPeriodicallyBounded

      public static void runPeriodicallyBounded(Runnable code, Duration duration, Duration maxTime)
      Runs certain code periodically but with a final bound.
      Parameters:
      code - the runnable that needs to be executed
      duration - the delay
      maxTime - the duration this thread will be opened in milliseconds
    • runPeriodicallyBounded

      public static void runPeriodicallyBounded(Runnable code, Duration initialDelay, Duration duration, Duration maxTime)
      Runs certain code periodically but with a final bound.
      Parameters:
      code - the runnable that needs to be executed
      initialDelay - the initial delay
      duration - the delay
      maxTime - the duration this thread will be opened in milliseconds
    • buildAsync

      public static ExecutorService buildAsync()
      Builds a new thread using an ExecutorService, allowing various utility methods.
      Returns:
      the created thread
    • buildPeriodic

      public static ScheduledExecutorService buildPeriodic()
      Builds a new thread using an ScheduledExecutorService, allowing various utility methods.
      Returns:
      the created thread