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

Identifying Transaction timeout

 
Jaikiran Pai
Marshal
Pie
Posts: 10444
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have a SLSB with BMT. In one of the methods of this bean i start a transaction and set a timeout value on this transaction. Now whenever the timeout occurs, a exception(java.lang.Interrupted) is thrown. In case the Interrupted exception is because of transaction timeout, i would like to do some additional logic. Is there any way to identify that the Interrupted exception was because of timeout? I could not find any APIs on the UserTransaction or the InterruptedException, which would tell me that timeout had occured.
 
Ajith Kallambella
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When the time out occurs, I'd expect the transaction to be marked for rollback. You should be able to just check the status of the UserTransaction object.
 
Jaikiran Pai
Marshal
Pie
Posts: 10444
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'd expect the transaction to be marked for rollback


The transaction is indeed marked for rollback. But, is there any way through which i can say for sure that this is marked for rollback because of a timeout? The transaction may be marked for rollback for some other reasons as well.
 
Roger Chung-Wee
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check your server log.
 
Jaikiran Pai
Marshal
Pie
Posts: 10444
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, server logs will contain the timedout message. But as i stated:
In case the Interrupted exception is because of transaction timeout, i would like to do some additional logic.


So i would have to know that a timeout has occured, programatically. I went through the code in JBoss(the appserver that i am using) and found that on timeout of a transaction, it logs a WARN message and then invokes thread.interrupt().

This effectively means that the actual cause(timeout) is lost. And i guess,(after looking at the code of JBoss) i wont be able to identify the timeout of a transaction, programatically.
[ February 23, 2006: Message edited by: jaikiran pai ]
 
Ajith Kallambella
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



The transaction is indeed marked for rollback. But, is there any way through which i can say for sure that this is marked for rollback because of a timeout? The transaction may be marked for rollback for some other reasons as well.


If you catch an InterruptedException *and* check whether the transaction is marked for roll back - you have narrowed it down pretty well isn't it? Isn't that sufficient for you? Granted that each one of these conditions can happen independently( an InterruptedException being thrown and transaction rolling back) for separate reasons. But when they both occur at the same time, you can be pretty sure it *is* what you're looking for.
 
Jaikiran Pai
Marshal
Pie
Posts: 10444
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But when they both occur at the same time, you can be pretty sure it *is* what you're looking for.


You are right, this is a fair enough solution. Thanks a lot.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic