Class ThreadUtils

java.lang.Object
io.github.thebusybiscuit.slimefun4.utils.ThreadUtils

public class ThreadUtils extends Object
  • Constructor Details

    • ThreadUtils

      public ThreadUtils()
  • Method Details

    • getMainThreadExecutor

      public static Executor getMainThreadExecutor()
    • getMainDelayedExecutor

      public static Executor getMainDelayedExecutor()
    • executeSync

      public static void executeSync(Runnable runnable)
      Executes a task synchronously on the main thread. If the current thread is already the main thread, the task runs immediately. Otherwise, the task is scheduled to run on the main thread.
      Parameters:
      runnable - The task to execute synchronously
    • executeSyncSched

      public static void executeSyncSched(Runnable runnable)
      Executes a task synchronously on the main thread with scheduling. If the current thread is already the main thread, the task is scheduled for later execution. Otherwise, the task is scheduled to run on the main thread.
      Parameters:
      runnable - The task to execute synchronously
    • getFutureTask

      public static <T> FutureTask<T> getFutureTask(Callable<T> callable)
      Creates a FutureTask from a Callable.
      Type Parameters:
      T - The type of the result
      Parameters:
      callable - The callable to wrap
      Returns:
      A FutureTask wrapping the callable
    • getFutureTask

      public static FutureTask<Void> getFutureTask(Runnable runnable)
      Creates a FutureTask from a Runnable. If the input is already a FutureTask, it is cast and returned. Otherwise, a new FutureTask is created with the Runnable and null result.
      Parameters:
      runnable - The runnable to wrap
      Returns:
      A FutureTask wrapping the runnable
    • getFutureTask

      public static <T> FutureTask<T> getFutureTask(Runnable runnable, T val)
      Creates a FutureTask from a Runnable with a specific result value.
      Type Parameters:
      T - The type of the result
      Parameters:
      runnable - The runnable to execute
      val - The result value to return
      Returns:
      A FutureTask that executes the runnable and returns the specified value