[jboss-user] [EJB/JBoss] - Handling Application Exceptions within MDBs and EJBs

idhira do-not-reply at jboss.com
Tue Apr 28 08:26:27 EDT 2009


I am running JBoss 4.2.3 with JBoss Messaging 1.4.2.GA-SP1

This is related to Container Managed Transactions and handling Application Exceptions within EJBs and MDBs.

The following are the exceptions I use:
MyRetryException - Extends Exception
MyEJBRetryRuntimeException - Extends Runtime Exception.  Annotated with @ApplicationException ( rollback = false )

The following represents a scenario I am testing.

public class myMDB implements MessageListener
  | {
  |     @EJB
  |     MyEJB myEJB;
  | 
  |     public void onMessage( Message msg )
  |     {
  | 
  |         try
  |         {
  |             myEJB.process(); // uses the transaction from the MDB
  |         }
  |         catch ( MyEJBRetryRuntimeException e )
  |         {
  |             myEJB.handleException( e ); // starts a new transaction
  |             throw e; // I want this message to be redelivered
  |         }
  |     }
  | }

In myEJB...
@TransactionAttribute( TransactionAttributeType.SUPPORTS )
  | public void process()
  | {
  |     try
  |     {
  |         throw new MyRetryException ("test");
  |     }
  |     catch ( MyRetryException e )
  |     {
  |         throw new MyEJBRetryRuntimeException(e);
  |     }
  | }
  | 
  | @TransactionAttribute( TransactionAttributeType.REQUIRES_NEW )
  | public void handleException( Exception ex )
  | {
  |     Connection conn = datasource.getConnection(); <-- throws an exception.
  | 
  | }

The handleException method tries to obtain a jdbc connection but throws the exception: javax.resource.ResourceException: Interrupted while requesting permit! Waited 0 ms.

According to http://www.jboss.org/community/docs/DOC-10001 it seems that i would get this error when a transaction is rolled back but I am throwing an ApplicationException with rollback = false.  Is there something I'm not doing right?  Any help would be appreciated.


View the original post : http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4227276#4227276

Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4227276



More information about the jboss-user mailing list