• 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
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Catching a timeout exception when using CMT

 
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Note: I'm using CMT on JBoss 3.2.3

I'm trying to think of a way to somehow catch a timeout exception. It happens rarely and we can easily increase the timeout time to avoid it, but it has got me thinking of how to catch a timeout exception so that we can respond to the exception in a more constructive way (as opposed to just an exception in the log).

On the JBoss wiki this is suggested:

http://wiki.jboss.org/wiki/Wiki.jsp?page=WhatIsTheCorrectPatternForUserTransactions

However I think I'm correct in thinking that though the code at the bottom would help (via the finally block), this is purely for BMT.

Can anyone suggest anything?

Thanks.
 
Ranch Hand
Posts: 704
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Dean,

It works with CMT as well. Inside of any business method you need to catch the TransactionTimeoutException, call the EJBContext.setRollbackOnly() and finally rethrow an application exception. This way you can give the client the opportunity to retry the transaction.
By the way the only thing that I don't like about the code on the jboss wiki site, is that it catches all generic Exception(s). From a designing standpoint this might not be the brightest idea.
Regards.
 
Dean Pullen
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But I thought the 'UserTransaction ut' was only available when dealing with BMT?
 
Valentin Tanase
Ranch Hand
Posts: 704
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Dean,


But I thought the 'UserTransaction ut' was only available when dealing with BMT?


That�s correct. The only way one can rollback a transaction in CMT is to call the setRollbackOnly on the EJB context object. The code might look like this:
[code]
public void doSomeBusinessLogic() {
try {
// Data access logic here. The next methods are not allowed with CMT:
// 1. The commit, setAutoCommit, and rollback methods of java.sql.Connection
// 2. The getUserTransaction method of javax.ejb.EJBContext
// 3. Any method of javax.transaction.UserTransaction
...
} catch (TransactionTimeoutException ex) {
log.error(...);
context.setRollbackOnly(); // Allowed !!
throw new SomeApplicationException();
}
}
[code]
Regards.
 
You didn't tell me he was so big. Unlike this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic