Anthony Vinay
Anthony Vinay

Reputation: 656

Does @Asynchronous in EJB 3.1 closes/releses the connection when the Async method is completed

In the EJB 3.1, we have annotated a method with @Asynchronous and using Future.get to fetch the results.

Question is when we do future.get(), does the database connections from the connection pool and resources are released which was being used in that async method?

Upvotes: 1

Views: 901

Answers (2)

Frito
Frito

Reputation: 446

Database connections are closed according to your configured connection pooling policy of the used application server.

When talking about session beans and container managed transactions, the connection is returned at the end to the transaction scope of the called business method.

Since session beans with @Asynchronous annotations do not support transaction propagation (e.g. see EJB 3.2 spec 4.5.3), a new transaction is created with every call to a business method if the method is configured with REQUIRED or REQUIRES_NEW. Thus, this transaction scope ends with the called business method returning.

Upvotes: 3

Gab
Gab

Reputation: 8332

There is a chance they are :) Otherwise using @Asynchronous would quickly lead to application crash due to lack of resources...

Anyway as resources are stored using Thread Local storage in Java-ee and as @Asynchronous defer the execution to a dedicated thread, the resources used there (including JCA Connection - and so database one) are also dedicated to the @Asynchronous method execution (not inherited from the caller thread).

Upvotes: 2

Related Questions