Thread creation by TreeCache
mraccola May 10, 2006 1:06 PMI am using JBoss TreeCache in a non-JBoss application server. JBoss is creating threads which use the JTA transaction manager. I guess the main use would be the eviction thread.
Apparently this is prohibited by the J2EE spec and frowned upon by the servlet specification. I have included some text from the IBM documentation below. Is this taken into consideration by TreeCache? Perhaps the integration with the application servers thread pool works OK with JBoss application server, but what about other J2EE containers? My understanding was the TreeCache could be used in any container?
The issue is I am having is it appears that some JTA transactions are hanging when I stop the application server. I am assuming the transactions are hanging because they are being managed by a thread which the application container does not know about, so the shutdown is not clean. Can someone enlighten me if I am wrong?
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.