• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

EJB 3.0 Nested Transaction Issue

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,
I am facing one issue while implementing Nested Transactions in EJB3.0

I am using contained managed persistence.

The transaction model that I am using for this is explained below:

I have an outer transaction having transation timeout of 10 minutes, it contains a "for loop" which calls another method of session bean that spawn new transaction using "Requires_New" having transation timeout of 5 minutes for each iteration as I need to commit database changes for each iteration independently.

Basic structure I am following
=====================
(Timeout is 10 min)
Outer Transaction
{
for loop
{
(Timeout is 5 min)
spawn a new transaction - (as need to commit independently for each iteration)
//It does some business logic
}
}

Now the problem that I am facing is, when the outer transaction timeout happens after 10 min then the "for loop" is not terminated rather than it continue the processing for remaining iterations also.

After 10 min when outer transaction timeout happens, following error occurs in the CONSOLE
10:18:10,540 INFO [CachedConnectionManager] Closing a connection for you. Please close them yourself: org.jboss.resource.adapter.jdbc.jdk6.WrappedConnectionJDK6@a1638f
java.lang.Throwable: STACKTRACE
at org.jboss.resource.connectionmanager.CachedConnectionManager.registerConnection(CachedConnectionManager.java:278)
at org.jboss.resource.connectionmanager.BaseConnectionManager2.allocateConnection(BaseConnectionManager2.java:524)


But "for loop" continues the processing for the remaining iterations. Once 'for loop" is done, the following error occurs
Caused by: javax.transaction.RollbackException: [com.arjuna.ats.internal.jta.transaction.arjunacore.inactive] [com.arjuna.ats.internal.jta.transaction.arjunacore.inactive] The transaction is not active!
at com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple.commitAndDisassociate(TransactionImple.java:1414)
at com.arjuna.ats.internal.jta.transaction.arjunacore.BaseTransaction.commit(BaseTransaction.java:137)
at com.arjuna.ats.jbossatx.BaseTransactionManagerDelegate.commit(BaseTransactionManagerDelegate.java:75)
at org.jboss.aspects.tx.TxPolicy.endTransaction(TxPolicy.java:170)


All the data got commited even after the above exception. Inner transaction timeout is handled perfectly but facing problem for outer transaction timeout.
But my requirement is when outer transaction timeout occurs, then for loop should terminate.Let suppose if outer transaction timeout occurs when inner transaction is processing the business logic, then that changes shuold sink with database, but when next iteration occurs then "for loop" should exit.Is it possible.
Waiting for reply.


Regards,
Abhishek
 
Ranch Hand
Posts: 544
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Abhishek,
First of all this is not the nested transaction. Please check this to understand more on Netsted Transactions. This is just one of the links I found on google.

When you call another transactional method ( Requires_new) in another SLSB, it suspends the existing transaction and then starts a new one.

Additionally your timeout in one method will not be able to stop the processing of another bean's method. There is no notification mechanism between them , isnt it?
For that you will need to poll some kind of variable which will tell you if timeout has happened and stop the FOR loop.

Regards,
Amit
 
Abhishek Bhargav
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for reply.
Is there any way to track the transaction state whether it is rollbacked or commited or timed out so that we can break the "for loop".

Regards
Abhishek
 
amit punekar
Ranch Hand
Posts: 544
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
I am not aware of such thing. In Stateful beans you can register the listener that has callback to listen for Transaction lifecyle events.
Apart from this I would like to know how you are setting the transaction timeout ? That might has some clue for the problem.

regards,
Amit
 
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Abhishek Bhargav wrote:
But my requirement is when outer transaction timeout occurs, then for loop should terminate.



Read this blog and the comments in that blog.
 
Abhishek Bhargav
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Yes the blog link is good in understanding how internally transaction timeout works, but the solution provided seemed to be a hard nut to crack.

I have set the transation timeout of outer and inner transaction using the annotation @TransactionTimeout(value = 600)

For outer transation I used it at class level @TransactionTimeout(value = 600), for inner transaction used it at method level @TransactionTimeout(value = 300).

Moreover I am using the stateless session bean not stateful.
Thanks for sharing your ideas.

Regards,
Abhishek
 
I do some of my very best work in water. Like this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic