ALB Studio

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

APIRuns onCall from
Database query/update/transaction...ALBCore DB threadsany thread; returns CompletableFuture
Database.migratethe calling thread (blocking)onEnable only
PlayerData getters / setin memory, thread-safeany thread
PlayerData.fetch / editbackgroundany thread; returns a future
GUI, MessageUtil, ItemBuilder, Vaultmain threadmain thread
PAPIHook.register handlersany 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:

Kotlin
db.queryFirst("SELECT level FROM ${db.table("level_players")} WHERE uuid = ?", player.uniqueId) { it.getInt(1) }
    .thenSync(plugin) { level -> player.sendMessage("Level ${level ?: 1}") }

Type a class, method, config key or topic. Use the arrow keys and Enter to open a result.