> For the complete documentation index, see [llms.txt](https://docs.aethercube.fr/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.aethercube.fr/developers/plugins/scheduler.md). Agents can also search and read this documentation through its [MCP server](https://docs.aethercube.fr/~gitbook/mcp).

# Scheduler

The scheduler is how you run something later, on a loop, or off the simulation thread. You reach it with `getServer().scheduler()`. The unit of time is the tick: 20 ticks make a second.

| Method                                               | Effect                                                        |
| ---------------------------------------------------- | ------------------------------------------------------------- |
| `runLater(owner, delayTicks, task)`                  | Runs `task` once after `delayTicks`. `0` means the next tick. |
| `runRepeating(owner, delayTicks, periodTicks, task)` | Runs `task` every `periodTicks`, starting after `delayTicks`. |
| `runAsync(owner, task)`                              | Runs `task` once on a worker thread.                          |
| `cancelAll(owner)`                                   | Cancels every task of `owner`.                                |

Each method returns a `Scheduler.Task` (except `cancelAll`) with `cancel()` and `cancelled()`. Pass your plugin (`this`) as the owner. The server cancels the tasks of a plugin when it is disabled.

```java
// every 10 seconds, on the simulation thread
Scheduler.Task announce = getServer().scheduler().runRepeating(this, 200, 200, () ->
        getServer().broadcast("Remember to rest at a campfire."));

// later
announce.cancel();
```

The scheduling methods may be called from any thread.

## Synchronous tasks

`runLater` and `runRepeating` tasks run on the simulation thread during the plugin phase of a tick, in order of due tick and then of submission. They may touch game state.

An exception in a task is logged and counted. Other tasks still run. The repeating task keeps its schedule.

The simulation thread cannot interrupt a task. A synchronous task that takes more than 10 ms is reported in the log with its owner. Keep each task short, and split a long job across ticks.

## Asynchronous tasks

`runAsync` tasks run on a worker pool. They must not read or write game state. Use them for work that waits: a file, a network call, a heavy computation. Return to the simulation thread with `runLater` to apply the result. See [Lifecycle and threads](https://docs.aethercube.fr/developers/plugins/lifecycle-and-threads.md) for the pattern.

The server records the CPU time of each plugin's events and tasks. See [Performance and metrics](https://docs.aethercube.fr/developers/running-a-server/performance-and-metrics.md).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.aethercube.fr/developers/plugins/scheduler.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
