|
Hi!
I have the foolowing question:
Supose I have, for example, 2
bean-managed persistence entity bean instances in a pool. A client
create a new entity and one of them is used. While it is being created, the bean
instance gets a data source and opens a connection. In some way
(perhaps storing it in another bean) the entity saves the connection.
Then the second bean instance in the pool is activated; before creating a new
connection it checks to see if there is a saved connection (in the place where
the other instance saved it). The connection is already there, so the second
bean uses it. Supose then that both instances where used in different
transactional contexts. When the first got the connection the corresponding
XAResource was enlisted with the first transaction. When the second reused the
connection it was already enlisted with the first transaction (I can't see a
place where a hook to stop/start the XAResource could be). The JTA specification
says:
"Different Java threads may be using the
same connection resource to access the resource manager if the connection spans
multiple method invocation [...] it's possible for different threads to be
invoking the XAResource start and end methods [...] If the applcation server
allows multiple threads to use a singe XAResource object and the associated
connection to the resource manager, it is the responsability of the application
server to ensure that there is only one transaction context asociated with the
resource at any point of time"
The EJB specification says:
"Because this resource factories allow the
Container to affect resource management, the connections acquired through the
resource manager connection factory are called managed resources (these resource
factories allow the Container to implement connection pooing and
!!!automatic enlistment of the connection with a transaction!!!)."
From this I couldn't not conclude that
providing a special factory is the only way for a Container to asociate a
XAResource with a transaction. But it says almost that, doesn't it?.
So:
1) The scenario I described above is wrong -I mean, something
in it is not possible- (I'm new with EJB).
2) EJB does't support "multiple threads to use a singe
XAResource" so I should avoid the scenario.
3) The scenario is possible and EJB implementations have more
tricks than those resource factories to reasociate (stop/start) XAResource with
transactions.
(I could be a little off-topic because the
question doesn't directly refer to jBoss. Sorry if this is the case: don't
answer me. Or answer me if jBoss supports multiple threads with... :) )
Thank you in advance, Carlos.
|
- Re: [jBoss-Dev] Threads, transactions and XAResources Carlos Pita
- Re: [jBoss-Dev] Threads, transactions and XAResources Rickard �berg
