Threading rules
Which ALBCore APIs run where, and how to keep slow work off the main thread.
Docs updated · What changed
On this page
The main thread runs the game. Anything slow on it (disk, network, database) makes the whole server lag. ALBCore is built so that you never have to block it.
Where each API runsLink to this section
| API | Runs on | Call from |
|---|---|---|
Database query/update/transaction... | ALBCore DB threads | any thread; returns CompletableFuture |
Database.migrate | the calling thread (blocking) | onEnable only |
PlayerData getters / set | in memory, thread-safe | any thread |
PlayerData.fetch / edit | background | any thread; returns a future |
GUI, MessageUtil, ItemBuilder, Vault | main thread | main thread |
PAPIHook.register handlers | any thread (TAB, scoreboards) | must be thread-safe |
Back to the main threadLink to this section
To use a database result with the Bukkit API, hop back to the main thread with thenSync:
db.queryFirst("SELECT level FROM ${db.table("level_players")} WHERE uuid = ?", player.uniqueId) { it.getInt(1) }
.thenSync(plugin) { level -> player.sendMessage("Level ${level ?: 1}") }