Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

difference between userTransaction.rollback() & userTransaction timeout

 
Sajid Moinuddin
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I am using stateful session bean and BMT to manage my transaction. I am keeping an open transaction in one of my method. I am expecting the user to call a second method to commit/rollback the transaction. Now, If the user doesn't call the second method, I am setting the transaction timeout. I want the transaction to be discarded if the user doesn't call the second method by 5 seconds. I am expecting the same behavior as the rollback(). Now, though my transaction times out, it doesn't release the locks on db / other resources like it does in case of roll back. Now, What is the difference between timeout and rollback? How can I discard my transaction if user doesn't call the second method??(should i use timer service!!)

regards,
Sajid
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When it Times Out, doesn't it throw an Exception. Then you can just Catch the Exception and roll it back. right?

Mark
 
Sajid Moinuddin
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
methodA(){
UserTransaction ut = sessionContext.getUserTransaction();
ut.setTimeout(5);
ut.begin();

//do some work here

}

methodB(){
UserTransaction ut = sessionContext.getUserTransaction();

//do some work here


ut.commit(); / ut.rollback();
}

I don't get any exception when the transaction times out. Is it supposed to throw any? Where exactly am i supposed to get the exception??
In the stateful session bean, in my method A , the transaction begins & remains open. In method B, the transaction is supposed to rollback/commit. I am keeping an open transaction across methods. That's not a good idea, I know. But I have to do this.
I am expecting if the user doesn't call method B & commits/rollbacks, withing 5 seconds, the transaction be rolled back. But the transaction is not rolling back & holds the lock on database & other resource if user doesn't call method B.

I am using Jboss & mysql. Is this some bug of jboss?? Or my concept is wrong??
regards,
Sajid


I am using Jboss. Is my concept
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic