Interface MainThread
- All Superinterfaces:
Executor
Runs a mod's code on the server's main thread, which owns every game object. Tasks from other
threads are queued and run during the next ticks, within a time budget per tick
(
forge.toml); a task is never interrupted. Called on the main thread itself,
execute(Runnable) and submit(Callable) run the task immediately.
Callbacks of the returned futures run on the thread that completes them, which is the
main thread: submit(...).thenAcceptAsync(result -> ..., modThread()) moves the
follow-up work back. The main thread must never wait for another thread's result.
-
Method Summary
Modifier and TypeMethodDescriptionvoidRunstaskon the main thread.booleanWhether the calling thread is the main thread.voidQueuestaskto run on the main threadticksframes from now, also when called on the main thread.<T> CompletableFuture<T> Runstaskon the main thread; the future completes with its result or exception.
-
Method Details
-
execute
Runstaskon the main thread. An exception it throws is logged with the mod's id.- Specified by:
executein interfaceExecutor- Throws:
RejectedExecutionException- after the server started stopping
-
submit
Runstaskon the main thread; the future completes with its result or exception.- Throws:
RejectedExecutionException- after the server started stopping
-
runLater
Queuestaskto run on the main threadticksframes from now, also when called on the main thread.- Throws:
IllegalArgumentException- whenticksis less than 1
-
isMainThread
boolean isMainThread()Whether the calling thread is the main thread.
-