Search code examples
quarkusquarkus-panache

How to run a async database task in Quarkus


I want to start a long-running database operation in a new thread. So the persistence context must be available but there is no return value (or the return value is not needed). Usually i do:


@Inject
MyRepository panachRepo;

new Thread(() -> {
    panachRepo.cleanupDatabase();
});

how do i achieve this in quarkus?


Solution

  • @Inject
    ManagedExecutor managedExecutor;
    

    Then you can submit a task to it.

    managedExecutor.execute(() -> methodToExecute());