Class TaskManager

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

public abstract class TaskManager extends Object
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    Deprecated, for removal: This API element is subject to removal in a future version.
    Use taskManager() to get an instance.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
     
  • Method Summary

    Modifier and Type
    Method
    Description
    abstract void
    async(Runnable runnable)
    Run a task asynchronously.
    abstract void
    cancel(int task)
    Cancel a task.
    Get the public ForkJoinPool.
    abstract void
    later(Runnable runnable, int delay)
    Run a task later on the main thread.
    abstract void
    laterAsync(Runnable runnable, int delay)
    Run a task later asynchronously.
    void
    Deprecated, for removal: This API element is subject to removal in a future version.
    Deprecated without replacement as unused internally, and poor implementation of what it's designed to do.
    <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.
    void
    Deprecated, for removal: This API element is subject to removal in a future version.
    Deprecated without replacement as unused internally, and poor implementation of what it's designed to do.
    void
    parallel(Collection<Runnable> runnables, Integer numThreads)
    Deprecated, for removal: This API element is subject to removal in a future version.
    Deprecated without replacement as unused internally, and poor implementation of what it's designed to do.
    abstract int
    repeat(Runnable runnable, int interval)
    Run a repeating task on the main thread.
    abstract int
    repeatAsync(Runnable runnable, int interval)
    Run a repeating task asynchronously.
    void
    Disable async catching for a specific task.
    <T> T
    sync(RunnableVal<T> function)
    Quickly run a task on the main thread, and wait for execution to finish.
    <T> T
    sync(Supplier<T> function)
    Quickly run a task on the main thread, and wait for execution to finish.
    <T> T
    Run a task on the main thread when the TPS is high enough, and wait for execution to finish.
    <T> T
    syncWhenFree(Supplier<T> supplier)
    Run a task on the main thread when the TPS is high enough, and wait for execution to finish.
    abstract void
    task(Runnable runnable)
    Run a task on the main thread.
    Gets an instance of the TaskManager.
    void
    taskNow(Runnable runnable, boolean async)
    Run a task on the current thread or asynchronously.
    void
    Run a task as soon as possible not on the main thread.
    void
    Run a task as soon as possible on the main thread.
    void
    taskSoonMain(Runnable runnable, boolean async)
    Run a task on the main thread at the next tick or now async.
    void
     
    void
    wait(AtomicBoolean running, int timeout)
    Deprecated, for removal: This API element is subject to removal in a future version.
    Deprecated without replacement as unused internally, and poor implementation of what it's designed to do.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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

      @Deprecated(forRemoval=true, since="2.7.0") public void parallel(Collection<Runnable> runables)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Deprecated without replacement as unused internally, and poor implementation of what it's designed to do.
      Run a bunch of tasks in parallel using the shared thread pool.
    • parallel

      @Deprecated(forRemoval=true, since="2.7.0") public void parallel(Collection<Runnable> runnables, @Nullable Integer numThreads)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Deprecated without replacement as unused internally, and poor implementation of what it's designed to do.
      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

      @Deprecated(forRemoval=true, since="2.7.0") public void wait(AtomicBoolean running, int timeout)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Deprecated without replacement as unused internally, and poor implementation of what it's designed to do.
    • notify

      @Deprecated(forRemoval=true, since="2.7.0") public void notify(AtomicBoolean running)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Deprecated without replacement as unused internally, and poor implementation of what it's designed to do.
    • 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