We're developing a system that have two main logics; One's a management logic, which is very light; and the other is a processing logic, which is very resource (RAM + CPU) consuming.
We decided to have one machine to run the management logic, and one (or more) other machine(s) to run the processing logic.
In order to separate the logics into different machines, we've created an application (EAR) for each logic, which gives us two separate applications.
Now, we're using Weblogic as our application server, and we haven't yet configured our domain to run the applications on different machines.
Before we do that, we want to know; When an EJB from the management application will call an EJB from the processing application, will the transaction propagate? If the management-EJB will rollback its transaction, will the processing-EJB will rollback it as well? Does this feature requires special configuration of the domain?
Yes. If you follow best practices and don't try anything silly, transactions and rollbacks will both propagate. That's exactly what EJBs are designed to do! If you need help on how to inject EJBs correctly using @EJB, a great guide is Mastering EJB3.1 or the short EJB3.0 refcard from JavaLobby.
EJBs use declarative transaction management, so you will need to make sure you put the correct declaration on your Bean:
@Stateless
@Remote({MyService.class})
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public class MyServiceBean implements MyService {
...awesome code here
}
One important note is that you need to have a Top Level EJB start your transaction for you and chain all the calls to other EJBs, or you need to start a transaction manually before calling multiple EJBs.
If you're in a servlet, and you call 6 EJBs annotated with REQUIRED
, you'll get 6 transactions, because the transaction boundary begins at each call to an EJB, and ends with the method exists.
If you're in an EJB, and you call 6 additional EJBs annotated with REQUIRED
, you'll get one transaction because the transaction boundary was started already.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With