Class TaskManager

java.lang.Object
com.fastasyncworldedit.core.util.TaskManager

public abstract class TaskManager extends Object
  • Field Details

  • Constructor Details

    • TaskManager

      protected TaskManager()
  • Method Details

    • taskManager

      public static TaskManager taskManager()
      Gets an instance of the TaskManager.
      Returns:
      an instance of the TaskManager
      Since:
      2.0.0
    • repeat

      public abstract int repeat(@Nonnull Runnable runnable, int interval)
      Run a repeating task on the main thread.
      Parameters:
      runnable - the task to run
      interval - in ticks
    • repeatAsync

      public abstract int repeatAsync(@Nonnull Runnable runnable, int interval)
      Run a repeating task asynchronously.
      Parameters:
      runnable - the task to run
      interval - in ticks
      Returns:
      the task id number
    • async

      public abstract void async(@Nonnull Runnable runnable)
      Run a task asynchronously.
      Parameters:
      runnable - the task to run
    • task

      public abstract void task(@Nonnull Runnable runnable)
      Run a task on the main thread.
      Parameters:
      runnable - the task to run
    • getPublicForkJoinPool

      public ForkJoinPool getPublicForkJoinPool()
      Get the public ForkJoinPool. - ONLY SUBMIT SHORT LIVED TASKS
      - DO NOT USE SLEEP/WAIT/LOCKS IN ANY SUBMITTED TASKS
    • parallel

      public void parallel(Collection<Runnable> runables)
      Run a bunch of tasks in parallel using the shared thread pool.
    • parallel

      @Deprecated public void parallel(Collection<Runnable> runnables, @Nullable Integer numThreads)
      Deprecated.
      Run a bunch of tasks in parallel.
      Parameters:
      runnables - the tasks to run
      numThreads - number of threads (null = config.yml parallel threads)
    • runUnsafe

      public void runUnsafe(Runnable run)
      Disable async catching for a specific task.
    • taskNow

      public void taskNow(@Nonnull Runnable runnable, boolean async)
      Run a task on the current thread or asynchronously. - If it's already the main thread, it will just call run()
      Parameters:
      runnable - the task to run
      async - whether the task should run on the main thread
    • taskNowMain

      public void taskNowMain(@Nonnull Runnable runnable)
      Run a task as soon as possible on the main thread. - Non blocking if not calling from the main thread
      Parameters:
      runnable - the task to run
    • taskNowAsync

      public void taskNowAsync(@Nonnull Runnable runnable)
      Run a task as soon as possible not on the main thread.
      Parameters:
      runnable - the task to run
      See Also:
    • taskSoonMain

      public void taskSoonMain(@Nonnull Runnable runnable, boolean async)
      Run a task on the main thread at the next tick or now async.
      Parameters:
      runnable - the task to run.
      async - whether the task should run on the main thread
    • later

      public abstract void later(@Nonnull Runnable runnable, int delay)
      Run a task later on the main thread.
      Parameters:
      runnable - the task to run
      delay - in ticks
    • laterAsync

      public abstract void laterAsync(@Nonnull Runnable runnable, int delay)
      Run a task later asynchronously.
      Parameters:
      runnable - the task to run
      delay - in ticks
    • cancel

      public abstract void cancel(int task)
      Cancel a task.
      Parameters:
      task - the id of the task to cancel
    • objectTask

      public <T> void objectTask(Collection<T> objects, RunnableVal<T> task, Runnable whenDone)
      Break up a task and run it in fragments of 5ms.
      - Each task will run on the main thread.
      Parameters:
      objects - the list of objects to run the task for
      task - the task to run on each object
      whenDone - when the object task completes
    • wait

      public void wait(AtomicBoolean running, int timeout)
    • notify

      public void notify(AtomicBoolean running)
    • taskWhenFree

      public void taskWhenFree(@Nonnull Runnable run)
    • syncWhenFree

      public <T> T syncWhenFree(@Nonnull RunnableVal<T> function)
      Run a task on the main thread when the TPS is high enough, and wait for execution to finish. - Useful if you need to access something from the Bukkit API from another thread
      - Usually wait time is around 25ms
    • syncWhenFree

      public <T> T syncWhenFree(@Nonnull Supplier<T> supplier)
      Run a task on the main thread when the TPS is high enough, and wait for execution to finish. - Useful if you need to access something from the Bukkit API from another thread
      - Usually wait time is around 25ms
    • sync

      public <T> T sync(@Nonnull RunnableVal<T> function)
      Quickly run a task on the main thread, and wait for execution to finish. - Useful if you need to access something from the Bukkit API from another thread
      - Usually wait time is around 25ms
    • sync

      public <T> T sync(Supplier<T> function)
      Quickly run a task on the main thread, and wait for execution to finish. - Useful if you need to access something from the Bukkit API from another thread
      - Usually wait time is around 25ms