“The EJB 2.0 and 2.1 specifications prohibit an EJB from managing threads. This includes starting, stopping, suspending and resuming threads.
EJB 2.0, Section 24.1.2 and EJB 2.1, Section 25.1.2 state the following:
Programming Restrictions
The enterprise bean must not attempt to manage threads. The enterprise bean must not attempt to start, stop, suspend, or resume a thread; or to change a thread’s priority or name. The enterprise bean must not attempt to manage thread groups.
For a servlet, the J2EE 1.3 and 1.4 specifications allow web components to create and manage threads, however, the execution and behavior of these threads must be tightly monitored by the application, not the application server. The specifications state the following:
J2EE 1.3 and J2EE 1.4:
J2EE.4.2.1.1 Transaction Requirements
If a web component creates a thread, the J2EE platform must ensure that the newly created thread is not associated with any JTA transaction.
J2EE.4.2.3 Transactions and Threads
JTA transactions should be started and completed in the thread in which the service method is called. Additional threads that are created for any purpose should not attempt to start JTA transactions.”
Partager