Reputation: 4297
What will happen when DbConnection.close() is called for a XA Reource? Will it be returned to the connection pool or will it be held by the transaction manager until the Global Transaction finishes?
Upvotes: 2
Views: 1269
Reputation: 11627
I have been cracking my head and looking for so many place for the answer, but none can give me a confirmation.
Most of time, the actual Transaction Manager behavior is vendor-dependent. But you can refer to the JTA 1.1 Specification too for the standard behavior.
- Assuming a client invokes an EJB bean with a TX_REQUIRED transaction attribute and the client is not associated with a global transaction, the EJB container starts a global transaction by invoking the TransactionManager.begin method.
- After the the transaction starts, the container invokes the bean method. As part of the business logic, the bean requests for a connection-based resource using the API provided by the resource adapter of interest.
- The application server obtains a resource from the resource adapter via some ResourceFactory.getTransactionalResource method.
- The resource adapter creates the TransactionalResource object and the associated XAResource and Connection objects.
- The application server invokes the getXAResource method.
- The application server enlists the resource to the transaction manager.
- The transaction manager invokes XAResource.start to associate the current transaction to the resource.
- The application server invokes the getConnection method.
- The application server returns the Connection object reference to the application.
- The application performs one or more operations on the connection.
- The application closes the connection.
- The application server delist the resource when notified by the resource adapter about the connection close.
- The transaction manager invokes XAResource.end to disassociate the transaction from the XAResource.
- The application server asks the transaction manager to commit the transaction.
- The transaction manager invokes XAResource.prepare to inform the resource manager to prepare the transaction work for commit.
- The transaction manager invokes XAResource.commit to commit the transaction.
So to answer you question, while you call the close()
, the connection will be delisted, it is somehow still being hold by the Transaction Manager, so you can safely call close()
before commit to pre-return the connection to the pool (if you worry about connection leak), although there are lot of Transaction Manager will help to auto-close the connection without you to manually close it (refer to Hibernate framework and Transaction Manager).
Upvotes: 3