Aller au contenu

Orm Call In Async Or Concurrent Context (ARCH4043)

Ce contenu n’est pas encore disponible dans votre langue.

Key java.async.jpa-session-in-async · Severity warning · Category async

When a synchronous JPA/ORM database call runs inside an async task or spawned thread, it blocks that thread and typically creates sharing problems with the thread-bound EntityManager session.

CompletableFuture.runAsync(() -> {
User u = entityManager.find(User.class, id); // blocking sync ORM
process(u);
});
CompletableFuture.supplyAsync(() -> {
return repository.findById(id); // dedicated executor + scoped EM
}, dbExecutor).thenAccept(this::process);

Run blocking ORM calls on a dedicated database executor and never share an EntityManager across threads.