In Java EE development, spawning custom threads within the container is generally discouraged. Understanding the rationale behind this prohibition helps clarify optimal development practices.
Java EE containers tightly manage and monitor resources within their environment. Creating custom threads disrupts this management, as they lack access to the thread-specific context essential for accessing JNDI resources like JMS Connection Factories and Datasources.
Despite the need for asynchronous tasks like mail distribution and cleanup jobs, there are appropriate ways to achieve this within Java EE containers:
Note that the discouragement of spawning threads in Java EE containers was more relevant in earlier versions (circa 2009). Advancements in Java EE have since improved support for asynchronous processing and managed thread pools. However, understanding the underlying reasons for the historical discouragement remains valuable for comprehension and adherence to recommended development practices.
The above is the detailed content of Why Are Custom Threads Discouraged in Java EE Containers?. For more information, please follow other related articles on the PHP Chinese website!