This content has been marked as final.
Show 3 replies
-
1. Re: Transaction timeout configuration for a specific Statele
cvandyck Aug 9, 2004 12:10 PM (in response to herbherby)You will only be able to do this if you use bean managed transactions.
In your session bean, here's some starter methods that you can use to start and end your transactions:protected int beginTransactionIfRequired(int timeoutInSeconds) { UserTransaction tran = this.sessionContext.getUserTransaction(); int initialTranStatus; try { initialTranStatus = tran.getStatus(); switch (initialTranStatus) { case Status.STATUS_ACTIVE: // we are ok just using the current transaction. break; case Status.STATUS_NO_TRANSACTION: // create a new transaction. try { this.sessionContext.getUserTransaction().setTransactionTimeout(timeoutInSeconds); tran.begin(); } catch (NotSupportedException e) { throw new EJBException("Unable to start transaction: " + e.getMessage()); } break; default: throw new EJBException("Transaction status invalid, status is: " + initialTranStatus); } } catch (SystemException e) { throw new EJBException("Unable to begin transaction",e); } return initialTranStatus; } protected void completeTransactionIfRequired(int initialTransactionStatus) { UserTransaction tran = this.sessionContext.getUserTransaction(); if (initialTransactionStatus == Status.STATUS_NO_TRANSACTION) { try { if (tran.getStatus() == Status.STATUS_MARKED_ROLLBACK) { tran.rollback(); } else { tran.commit(); } } catch(Exception e) { throw new EJBException("Unable to complete transaction",e); } } }
-
2. Re: Transaction timeout configuration for a specific Statele
herbherby Aug 10, 2004 5:21 AM (in response to herbherby)Thanx Collin, I will try that, even though I can't understand why this feature isn't possible with Container Managed Transactions !? ...
-
3. Re: Transaction timeout configuration for a specific Statele
starksm64 Aug 10, 2004 10:24 PM (in response to herbherby)jboss-3.2.5 supports method level tx timeouts.
<?xml version="1.0"?> <jboss> <enterprise-beans> <session> <ejb-name>TxTimeout</ejb-name> <jndi-name>jbosstest/tm/TxTimeout</jndi-name> <method-attributes> <method> <method-name>testOverriddenTimeoutExpires</method-name> <transaction-timeout>5</transaction-timeout> </method> <method> <method-name>testOverriddenTimeoutDoesNotExpire</method-name> <transaction-timeout>20</transaction-timeout> </method> </method-attributes> </session> </enterprise-beans> </jboss>