When I was working on a J2EE project at
NovaMSC, I decided to solve a problem of asynchronous invocation of time-consuming report generation by spawning new thread in the web component,
servlet. Initially, the problem was supposed to be solved by using
JMS, but due to the time constraint, I insisted on the simpler solution.
After implementing the solution, I received a lot of negative feedbacks and comments about it but I didn’t even bother to reconsider for change because 1) no time, seriously and 2) I didn’t get any fact saying that that was totally a bad idea of spawning normal java thread in web component (especially the thread is designed to call the business component,
EJB component).
Until recently I read the J2EE spec and realized that I was really wrong, here is the excerpt in the
spec:
“If a web component creates a thread, the Java EE platform must ensure that the newly created thread is not associated with any JTA transaction.”
This statement means that if anything goes wrong in the middle of the transaction, nothing will get rollback (it might not mean exactly the same, further findings will be posted).
Hopefully everything is going fine currently.