Execution of the same transaction in several threads

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Execution of the same transaction in several threads

Pavel Vlasov
Hello,

I'm working on a flow execution engine in which processing can be performed in multiple threads. I'm trying to understand how a transaction can be propagated between threads so more than one thread concurrently work in the context of the same global transaction. It is allowed by the spec: "Multiple threads may concurrently be associated with the same global transaction." - JTA spec v1.1, section 3.2, page 13.

However, the only way to propagate a transaction which I've found so far is TransactionManager.resume(Transaction) and this method dissociates the transaction from the original thread. I guess that one thread shall start a transaction and other thread shall join it rather than resume, but I can't find a way to accomplish this. The flow engine is not running in the app server, so I'm calling TransactionManager explicitly.

Can you please point me in the right direction?
---
Thank you Pavel.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Execution of the same transaction in several threads

Pavel Vlasov
"TransactionManager.resume(Transaction) and this method dissociates the transaction from the original thread" - it appears to be an incorrect statement, my apologies. My understanding was that it is mandatory to suspend transaction in on thread in order to resume in another. It seems that it is OK to pass transaction object between threads, can you please confirm?

On 3/30/2013 3:46 PM, Pavel Vlasov wrote:
Hello,

I'm working on a flow execution engine in which processing can be performed in multiple threads. I'm trying to understand how a transaction can be propagated between threads so more than one thread concurrently work in the context of the same global transaction. It is allowed by the spec: "Multiple threads may concurrently be associated with the same global transaction." - JTA spec v1.1, section 3.2, page 13.

However, the only way to propagate a transaction which I've found so far is TransactionManager.resume(Transaction) and this method dissociates the transaction from the original thread. I guess that one thread shall start a transaction and other thread shall join it rather than resume, but I can't find a way to accomplish this. The flow engine is not running in the app server, so I'm calling TransactionManager explicitly.

Can you please point me in the right direction?
---
Thank you Pavel.

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Execution of the same transaction in several threads

Ludovic Orban-2
I'm sorry for the long delay getting back to you,

Yes: you can pass the Transaction objects between threads. The common pattern is to call TransactionManager.suspend() on thread A and TransactionManager.resume() on thread B, and that happily works.

I'm not sure what the JTA spec v1.1 section 3.2 is meant to say. I can tell you that this is contradicting some implicit requirements and doesn't make much sense: how can one re-associate a transaction to a thread? Calling TransactionManager.resume() is the only way but from the top of my head, resume() is supposed to call XAResource.start(TMRESUME) on all enlisted XAResources. I could be wrong but that feature overload definitely is pushed a bit far.

In a nutshell: I don't know if that would work with BTM, I don't know if any TM out there supports that or not but I'm quite confident that having two threads working in parallel on a single transaction is a terrible, terrible idea as I don't think a single resource out there would support that (think JDBC drivers and JMS).



On Sun, Mar 31, 2013 at 3:38 AM, Pavel Vlasov <[hidden email]> wrote:
"TransactionManager.resume(Transaction) and this method dissociates the transaction from the original thread" - it appears to be an incorrect statement, my apologies. My understanding was that it is mandatory to suspend transaction in on thread in order to resume in another. It seems that it is OK to pass transaction object between threads, can you please confirm?

On 3/30/2013 3:46 PM, Pavel Vlasov wrote:
Hello,

I'm working on a flow execution engine in which processing can be performed in multiple threads. I'm trying to understand how a transaction can be propagated between threads so more than one thread concurrently work in the context of the same global transaction. It is allowed by the spec: "Multiple threads may concurrently be associated with the same global transaction." - JTA spec v1.1, section 3.2, page 13.

However, the only way to propagate a transaction which I've found so far is TransactionManager.resume(Transaction) and this method dissociates the transaction from the original thread. I guess that one thread shall start a transaction and other thread shall join it rather than resume, but I can't find a way to accomplish this. The flow engine is not running in the app server, so I'm calling TransactionManager explicitly.

Can you please point me in the right direction?
---
Thank you Pavel.


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

RE: Execution of the same transaction in several threads

Vlasov, Pavel

Thank you for clarifications! My question was primarily about the ability of the transaction manager to handle a single transaction in multiple threads, while resource managers may be invoked each from a single thread with each thread participating the same transaction.

 

From: [hidden email] [mailto:[hidden email]] On Behalf Of Ludovic Orban
Sent: Thursday, April 25, 2013 4:16 AM
To: [hidden email]
Subject: Re: [btm-user] Execution of the same transaction in several threads

 

I'm sorry for the long delay getting back to you,

Yes: you can pass the Transaction objects between threads. The common pattern is to call TransactionManager.suspend() on thread A and TransactionManager.resume() on thread B, and that happily works.

 

I'm not sure what the JTA spec v1.1 section 3.2 is meant to say. I can tell you that this is contradicting some implicit requirements and doesn't make much sense: how can one re-associate a transaction to a thread? Calling TransactionManager.resume() is the only way but from the top of my head, resume() is supposed to call XAResource.start(TMRESUME) on all enlisted XAResources. I could be wrong but that feature overload definitely is pushed a bit far.

In a nutshell: I don't know if that would work with BTM, I don't know if any TM out there supports that or not but I'm quite confident that having two threads working in parallel on a single transaction is a terrible, terrible idea as I don't think a single resource out there would support that (think JDBC drivers and JMS).

 

On Sun, Mar 31, 2013 at 3:38 AM, Pavel Vlasov <[hidden email]> wrote:

"TransactionManager.resume(Transaction) and this method dissociates the transaction from the original thread" - it appears to be an incorrect statement, my apologies. My understanding was that it is mandatory to suspend transaction in on thread in order to resume in another. It seems that it is OK to pass transaction object between threads, can you please confirm?

On 3/30/2013 3:46 PM, Pavel Vlasov wrote:

Hello,

I'm working on a flow execution engine in which processing can be performed in multiple threads. I'm trying to understand how a transaction can be propagated between threads so more than one thread concurrently work in the context of the same global transaction. It is allowed by the spec: "Multiple threads may concurrently be associated with the same global transaction." - JTA spec v1.1, section 3.2, page 13.

However, the only way to propagate a transaction which I've found so far is TransactionManager.resume(Transaction) and this method dissociates the transaction from the original thread. I guess that one thread shall start a transaction and other thread shall join it rather than resume, but I can't find a way to accomplish this. The flow engine is not running in the app server, so I'm calling TransactionManager explicitly.

Can you please point me in the right direction?
---
Thank you Pavel.

 

 

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Execution of the same transaction in several threads

Ludovic Orban-2
If what you want to do is suspend a transaction from one thread, then resume it on another one, then suspend it again then resume it on yet another thread and so on, then there's no problem at all: that will work just fine.


On Thu, Apr 25, 2013 at 3:16 PM, Vlasov, Pavel <[hidden email]> wrote:

Thank you for clarifications! My question was primarily about the ability of the transaction manager to handle a single transaction in multiple threads, while resource managers may be invoked each from a single thread with each thread participating the same transaction.

 

From: [hidden email] [mailto:[hidden email]] On Behalf Of Ludovic Orban
Sent: Thursday, April 25, 2013 4:16 AM
To: [hidden email]
Subject: Re: [btm-user] Execution of the same transaction in several threads

 

I'm sorry for the long delay getting back to you,

Yes: you can pass the Transaction objects between threads. The common pattern is to call TransactionManager.suspend() on thread A and TransactionManager.resume() on thread B, and that happily works.

 

I'm not sure what the JTA spec v1.1 section 3.2 is meant to say. I can tell you that this is contradicting some implicit requirements and doesn't make much sense: how can one re-associate a transaction to a thread? Calling TransactionManager.resume() is the only way but from the top of my head, resume() is supposed to call XAResource.start(TMRESUME) on all enlisted XAResources. I could be wrong but that feature overload definitely is pushed a bit far.

In a nutshell: I don't know if that would work with BTM, I don't know if any TM out there supports that or not but I'm quite confident that having two threads working in parallel on a single transaction is a terrible, terrible idea as I don't think a single resource out there would support that (think JDBC drivers and JMS).

 

On Sun, Mar 31, 2013 at 3:38 AM, Pavel Vlasov <[hidden email]> wrote:

"TransactionManager.resume(Transaction) and this method dissociates the transaction from the original thread" - it appears to be an incorrect statement, my apologies. My understanding was that it is mandatory to suspend transaction in on thread in order to resume in another. It seems that it is OK to pass transaction object between threads, can you please confirm?

On 3/30/2013 3:46 PM, Pavel Vlasov wrote:

Hello,

I'm working on a flow execution engine in which processing can be performed in multiple threads. I'm trying to understand how a transaction can be propagated between threads so more than one thread concurrently work in the context of the same global transaction. It is allowed by the spec: "Multiple threads may concurrently be associated with the same global transaction." - JTA spec v1.1, section 3.2, page 13.

However, the only way to propagate a transaction which I've found so far is TransactionManager.resume(Transaction) and this method dissociates the transaction from the original thread. I guess that one thread shall start a transaction and other thread shall join it rather than resume, but I can't find a way to accomplish this. The flow engine is not running in the app server, so I'm calling TransactionManager explicitly.

Can you please point me in the right direction?
---
Thank you Pavel.

 

 


Loading...