The spec. says an EJBshould not start/stop threads, i.e., create threads on its own. I also learned that it is because the container will have a hard time controlling transactions if that would happen.
However, I still do not understand why that is the case. Could someone give an example as to why creating multi-threads in EJB is a real issue. For example, let say my EJB creates two threads, simulating a parallel workflow. The EJB waits until both threads finish and then return, thus the container commits the transaction. So, that is fine, not an issue.
If one of the threads throws exception, it dies and EJB can catch that exception to mark the transaction as rollback only, etc., or rollback the transaction.
In addition, what if I use UserTransaction to manage my own transactions so that I can use multiple threads without worrying about interfering with container's transaction management? Would this be a better argument for using threads in EJB?
Again, I understand that using MDB is a better choice than multi-threads in EJB, but I wonder technically if there is a good reason not to do so.
Could someone point out specifically why that would be a problem?