File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes EJB and other Java EE Technologies and the fly likes Identifying Transaction timeout Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Identifying Transaction timeout" Watch "Identifying Transaction timeout" New topic
Author

Identifying Transaction timeout

Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10242
    
168

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.


[My Blog] [JavaRanch Journal]
Ajith Kallambella
Sheriff

Joined: Mar 17, 2000
Posts: 5782
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.


Open Group Certified Distinguished IT Architect. Open Group Certified Master IT Architect. Sun Certified Architect (SCEA).
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10242
    
168

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

Joined: Sep 29, 2002
Posts: 1683
Check your server log.


SCJP 1.4, SCWCD 1.3, SCBCD 1.3
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10242
    
168

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

Joined: Mar 17, 2000
Posts: 5782



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

Joined: Jul 20, 2005
Posts: 10242
    
168

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Identifying Transaction timeout