1 2 Previous Next 16 Replies Latest reply on Sep 23, 2010 2:33 PM by pablo.fraga1975 Go to original post
      • 15. Re: Can't get @TransactionTimeout to work
        jaikiran

        Pablo Fraga wrote:

         

        Hi,

        I have the same problem. I'am using EJB3, JBoss 4.2.3 GA, SLSB with CMP transactions.

        Code snap:

        import org.jboss.annotation.ejb.TransactionTimeout;

        @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
        @TransactionTimeout(15)
        public AbstractResult compra(AbstractCommand command){

        The timeout doesn't work for me using this annotation with this full qualified name.

        But the thing is that i can't find the other one in any jar provided by JBoss. Can't find org.jboss.ejb3.annotation.TransactionTimeout.

        Since you are using, AS 4.2.x, the annotation to use is org.jboss.annotation.ejb.TransactionTimeout.

         

        If that doesn't work, then please post relevant EJB code and the logs that indicate that the timeout isn't working.

        • 16. Re: Can't get @TransactionTimeout to work
          pablo.fraga1975

          Jaikiran,

           

          It doesn't work.

           

          This is mi relevant code.

           

          EJB3

           

          @Stateful(name = "DiccionarioEJB")
          @Remote(value = RemoteEJBService.class)
          public class DiccionarioEJB extends AbstractSessionFacade implements
                  DiccionarioRemote {

           

              private static Logger log = Logger.getLogger(DiccionarioEJB.class);

           

              @Resource(mappedName = "java:/smsds")
              private DataSource dataSource;

           

              @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
              @TransactionTimeout(500)
              public ResultObtenerDiccionario obtenerDiccionario(AbstractCommand command) {

           

                  testConnection();

           

                  try {

           

                      // sleeps 20 seconds
                      Thread.sleep(20000);

           

                      testConnection();

           

                  } catch (Throwable t) {
                      System.out.println("SUCCESS! Expected tx timeout error");
                      t.printStackTrace();
                      return null;
                  }

           

                  return null;

           

              }

           

              private void testConnection() {
                  Connection conn = null;
                  try {
                      conn = this.dataSource.getConnection();
                      System.out.println("Got connection");
                  } catch (Throwable t) {
                      System.out
                              .println("Error while getting connection from tx aware datasource: ");
                      throw new RuntimeException(t);
                  } finally {
                      if (conn != null) {
                          try {
                              conn.close();
                          } catch (SQLException e) {
                              System.out.println("Error closing connection "
                                      + e.getMessage());
                          }
                      }
                  }
              }

           

          }

           

          JTA timeout set to 10 seconds

           

          <!-- JBoss Transactions JTA -->
             <mbean code="com.arjuna.ats.jbossatx.jta.TransactionManagerService"
                name="jboss:service=TransactionManager">
                <attribute name="TransactionTimeout">10</attribute>
                <attribute name="ObjectStoreDir">${jboss.server.data.dir}/tx-object-store</attribute>
             </mbean>

           

          Log

           

          15:18:07,252 WARN  [arjLoggerI18N] [com.arjuna.ats.arjuna.coordinator.BasicAction_58] - Abort of action id 7f000101:a89c:4c9b9942:32 invoked while multiple threads active within it.
          15:18:07,252 WARN  [arjLoggerI18N] [com.arjuna.ats.arjuna.coordinator.CheckedAction_2] - CheckedAction::check - atomic action 7f000101:a89c:4c9b9942:32 aborting with 1 threads active!
          15:19:24,903 INFO  [STDOUT] Error while getting connection from tx aware datasource:
          15:19:25,740 INFO  [STDOUT] SUCCESS! Expected tx timeout error
          15:19:26,723 ERROR [STDERR] java.lang.RuntimeException: org.jboss.util.NestedSQLException: Transaction is not active: tx=TransactionImple < ac, BasicAction: 7f000101:a89c:4c9b9942:32 status: ActionStatus.ABORTED >; - nested throwable: (javax.resource.ResourceException: Transaction is not active: tx=TransactionImple < ac, BasicAction: 7f000101:a89c:4c9b9942:32 status: ActionStatus.ABORTED >)

           

          In my example the global transaction time out was set to 10 seconds, my EJB method is annotated with 500 seconds, the EJB method first testConnection, then sleeps 20 seconds and finally tries to connect again but it fails because the transaccion is not active anymore.

           

          What is wrong?

           

          Thanks.

          1 2 Previous Next