wood burning stoves 2.0*
The moose likes EJB and other Java EE Technologies and the fly likes difference between userTransaction.rollback() & userTransaction timeout Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "difference between userTransaction.rollback() & userTransaction timeout " Watch "difference between userTransaction.rollback() & userTransaction timeout " New topic
Author

difference between userTransaction.rollback() & userTransaction timeout

Sajid Moinuddin
Ranch Hand

Joined: Mar 19, 2005
Posts: 85
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

Joined: Feb 05, 2001
Posts: 17250
    
    6

When it Times Out, doesn't it throw an Exception. Then you can just Catch the Exception and roll it back. right?

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Sajid Moinuddin
Ranch Hand

Joined: Mar 19, 2005
Posts: 85
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
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: difference between userTransaction.rollback() & userTransaction timeout