sauumum
sauumum

Reputation: 1788

How transactions are managed internally inside EJB container?

As a programmer when I use container managed transactions, the only thing I am interested in what should be the transaction attribute i.e. REQUIRED, REQUIRED_NEW etc.

Someone asked me recently, how container manage all these transactions i.e what thread it used, what datastructure it uses to track all ongoing transaction ? I have not read any documents which describe this. Can you please try to explain this or share link of any tutorial related to this?

Upvotes: 2

Views: 190

Answers (1)

Brett Kail
Brett Kail

Reputation: 33946

Typically, the EJB container does not implement transaction management itself. Instead, it uses TransactionManager, which is typically implemented in a separate module. Depending on the implementation, there might not be any data structure at all: the EJB proxy could be as simple as calling getTransaction, suspend, or begin as needed (depending on the transaction attribute), storing the Transaction in a local variable, invoking the actual bean instance, and calling commit, rollback, or resume afterwards.

The TransactionManager almost certainly uses a ThreadLocal of some kind to store the current transaction, and it likely uses some kind of secondary thread to track transaction timeouts. The specific data structures used will otherwise vary widely depending on the implementation.

(I've never come across any documents that describe the internal workings of the transaction manager. Looking at an open source implementation might give some ideas of what kind of data structures can be used.)

Upvotes: 3

Related Questions