Note that there are some explanatory texts on larger screens.

plurals
  1. POREQUIRES_NEW within REQUIRES_NEW within REQUIRES_NEW ... on and on
    text
    copied!<p>JBoss 4.x<br> EJB 3.0</p> <p>I've seen code like the following (greatly abbreviated):</p> <pre><code>@Stateless @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED) public class EJB1 implements IEJB1 { @EJB private IEJB1 self; @EJB private IEJB2 ejb2; @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW) public boolean someMethod1() { return someMethod2(); } @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW) public boolean someMethod2() { return self.someMethod3(); } @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW) public boolean someMethod3() { return ejb2.someMethod1(); } } </code></pre> <p>And say EJB2 is almost an exact copy of EJB1 (same three methods), and <code>EJB2.someMethod3()</code> calls into <code>EJB3.someMethod1()</code>, which then finally in <code>EJB3.someMethod3()</code> writes to the DB.</p> <p>This is a contrived example, but have seen similar code to the above in our codebase. The code actually works just fine.</p> <p>However, it feels like terrible practice and I'm concerned about the <code>@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)</code> on every method that doesn't even actually perform any DB writes. Does this actually create a new transaction every single time for every method call with the result of:</p> <p>new transaction<br> -new transaction<br> --new transaction<br> ---new transaction<br> ...(many more)<br> -------new transaciton (DB write)</p> <p>And then unwraps at that point? Would this ever be a cause for performance concern? Additional thoughts?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload