Threading

An object useful for running multithreaded asynchronous code

Functions

Link copied to clipboard
inline fun contextBoundedRunAsync(name: String = "Worker Thread #", isDaemon: Boolean = false, crossinline runnable: ThreadContext.() -> Unit)

Runs provided task on another thread, with ThreadContext. This should not be used if called lots of times, e.g. in a loop, because creating of numerous ThreadContexts might cause a memory leak, in that case it is recommended to use runAsync, which is more lightweight

Link copied to clipboard
inline fun driftFromMain(crossinline runnable: () -> Unit)

Executes the code on separate thread if Thread.currentThread is the current Minecraft Server thread (MinecraftServer.serverThread), otherwise the code is run on current thread

Link copied to clipboard

Constructs a new cached thread pool, delegating to Executors.newCachedThreadPool

Link copied to clipboard

Constructs a new fixed thread pool, with max amount of active threads at once

Link copied to clipboard
inline fun runAsync(isDaemon: Boolean = false, crossinline runnable: suspend () -> Unit)

Runs provided task on another thread without ThreadContext, which provides better performance.

Link copied to clipboard
fun runEachConcurrently(service: ExecutorService = Executors.newCachedThreadPool(), vararg executors: () -> Unit)

Runs each of the provided executors concurrently

Properties

Link copied to clipboard

Amount of threads active at a time