Skip to content

How can I integrate Mutiny with my framework?#

Sometimes, Mutiny needs to execute tasks on other threads, such as monitoring time or delaying actions. Most operators relying on such capacity let you pass either a ScheduledExecutorService or an ExecutorService.

By default, Mutiny uses the a cached thread pool as default executor, that creates new threads as needed, but reuse previously constructed threads when they are available. A ScheduledExecutorService is also created but delegates the execution of the delayed/scheduled tasks to the default executor.

In the case you want to integrate Mutiny with a thread pool managed by a platform, you can configure it using Infrastructure.setDefaultExecutor() method:

1
2
3
4
5
6
7
Uni<Integer> uni1 = Uni.createFrom().item(1)
        .emitOn(Infrastructure.getDefaultExecutor());

Uni<Integer> uni2 = Uni.createFrom().item(2)
        .onItem().delayIt()
            .onExecutor(Infrastructure.getDefaultWorkerPool())
            .by(Duration.ofMillis(10));

You can configure the default executor using the Infrastructure.setDefaultExecutor method:

Infrastructure.setDefaultExecutor(executor);

Tip

If you are using Quarkus, the default executor is already configured to use the Quarkus worker thread pool. Logging is also configured correctly.