| Callable<Void> task = new Callable<Void>() { | |
| @Override | |
| public Void call() { | |
| try { | |
| DefaultAsyncMailer.this.mailer.send(email); | |
| } catch (EmailException e) { | |
| LOGGER.error( | |
| "Error while sending async email " | |
| + email.getSubject() + " to " | |
| + email.getToAddresses(), e); | |
| } | |
| return null; | |
| } | |
| }; | |
| return this.executor.submit(task); |
@ApplicationScoped
public class ExecutorServiceProvider {
private ExecutorService pool;
@PostConstruct
public void initialize() {
this.pool = Executors.newCachedThreadPool();
}
@Produces
public ExecutorService getInstance() {
return this.pool;
}
@PreDestroy
public void close(ExecutorService pool) {
this.pool.shutdown();
}
}--
Você recebeu essa mensagem porque está inscrito no grupo "caelum-vraptor" dos Grupos do Google.
Para cancelar inscrição nesse grupo e parar de receber e-mails dele, envie um e-mail para caelum-vrapto...@googlegroups.com.
Para postar nesse grupo, envie um e-mail para caelum-...@googlegroups.com.
Acesse esse grupo em https://groups.google.com/group/caelum-vraptor.
Para mais opções, acesse https://groups.google.com/d/optout.
org.jboss.weld.context.ContextNotActiveException: WELD-001303: No active contexts for scope type javax.enterprise.context.RequestScoped
EntityManager entityManager = factory.createEntityManager();
MeuDAO dao = new MeuDAO(entityManager);
Lembrando que como está fora do contexto da aplicação, o JPATransactionInterpector do VRaptor-JPA plugin não funciona aqui. Por isso, tive que gerenciar o transaction "manualmente" (foi um tempo até achar porque não salvava! haha)
Ficou assim:
//Iniciar transação com o banco de dados manualmente
EntityManager entityManager = factory.createEntityManager();
EntityTransaction entityTransaction = entityManager.getTransaction();
entityTransaction.begin();
... lógica com os dados
//Commit de alterações
if(entityTransaction != null && entityTransaction.isActive()) {
entityTransaction.commit();
}
Acho que agora está tudo ok! Obrigado.