Search code examples
transactionstimeoutejbwildfly

How is @TransactionTimeout handled by WildFly?


I am wondering how @TranscationTimeout is handled by WildFly, especially when invoking anothers EJB method annotated with @TransactionAttribute but not with @TransactionTimeout itself.

I have searched WildFly documentation, API Docs and of course googled, but I am not able to find any statements.

Consider the following scenario. We have stateless EJBs A and B.

@Stateless
public class A {

  @Inject
  private B b;

  @TransactionTimeout(unit = TimeUnit.MINUTES, value = 10)
  public void t() {
    b.t();
  }
}

@Stateless
public class B {

  @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
  public void t() {
  }
}

When invoked by client, I expect:

  • A::t runs within a transaction with a timeout of 10 minutes
  • B::t runs within a new transaction with the container default timeout (5 minutes in WildFly)
  • B::t within A::t runs in its own new transaction with the container default timeout (5 minutes in WildFly)

What happens:

  • B::t within A::t runs in its own new transaction with a timeout of 10 minutes

It seems that @TransactionTimeout is inherited to nested EJB methods if they are not annotated with @TransactionTimeout in some way respectively container default is overriden when they are called. Is this behavior wanted? Are there exceptions?

I am running WildFly 10.1.0 with Java 8.


Solution

  • As TransactionTimeout-Annotation states:

    "Annotation for specifying the transaction timeout of a newly started transaction when invoking an EJB business method"

    That means imO: for a newly started transaction, not for the currently running transaction. Therefore B:t is affected since it starts a new transaction, as possibly is A:t, but only if it is called out of a non transactional context. (default @Requires might mean, that the transaction is already running.)

    This would then fit to your observations.