jules
jules

Reputation: 437

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?

Upvotes: 1

Views: 1096

Answers (1)

sojin
sojin

Reputation: 4694

@Inject
ManagedExecutor managedExecutor;

Then you can submit a task to it.

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

Upvotes: 4

Related Questions