Atomikos Forum |
|
I'm evaluating TransactionEssentials for a project that has a requirement of using one transaction from multiple threads simultaneously. Is this even possible with JTA/XA?
(For those who think the problem is not valid, think of a transaction consisting of 50 service requests, each taking 50ms of (mostly) IO wait. The requirement is low latency. Doing the operations in sequence takes 2500ms, but with simultaneous threads around hundred or so milliseconds.) To limit the load to the service and to lower the latency from creating new threads, there is a VM-wide thread pool for serving the requests. in pseudocode, with main and service threads: 1 mainthread: tx=TransactionManager.getTransaction(); 2 srvsthread: TransactionManager.resume(tx); 3 srvsthread: ...process... 4 srvsthread: TransactionManager.??????????(); 5 mainthread: srvsthread.getResultWhenDone(); 6 mainthread: tx.commit(); Line 4, ??????????() is the problem. 1) If suspend() is used, tx.commit() will (obviously) fail with "java.lang.IllegalStateException: Transaction no longer active." 2) Another solution is to leave the line 4 out entirely which will cause "java.lang.IllegalStateException: Thread already has subtx stack" when the srvsthread is reused from the pool the next time. As I see it, there should be a way to disassociate a thread from the transaction without suspending the transaction to make this work. Am I correct?
suspend() works if the main thread is paused while the service thread runs. But it doesn't work if there are >1 service threads running concurrently. suspend() suspends the transaction for all the threads and the other threads will fail as mentioned above.
I think this is more of a problem with the JTA API than with the implementation. I'm just trying to see if there is a way to dance around it. JTA specification is vague enough to allow multiple simultaneous threads. It's just missing a method call or two to support it properly.=) |