J2EE Bad Practices: Direct Use of Threads |
Weakness ID: 383 (Weakness Variant) | Status: Draft |
Description Summary
Thread management in a Web application is forbidden in some circumstances and is always highly error prone.
Example 1
In the following example, a new Thread object is created and invoked directly from within the body of a doGet() method in a Java servlet.
(Bad Code)
Example Language: Java
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// Perform servlet tasks.
...
// Create a new thread to handle background processing.
Runnable r = new Runnable() {
public void run() {
// Process and store request statistics.
...
}
};
new Thread(r).start();
}
For EJB, use framework approaches for parallel execution, instead of using threads. |
Thread management in a web application is forbidden by the J2EE standard in some circumstances and is always highly error prone. Managing threads is difficult and is likely to interfere in unpredictable ways with the behavior of the application container. Even without interfering with the container, thread management usually leads to bugs that are hard to detect and diagnose like deadlock, race conditions, and other synchronization errors. |
Nature | Type | ID | Name | View(s) this relationship pertains to |
---|---|---|---|---|
ChildOf | Category | 361 | Time and State | Seven Pernicious Kingdoms (primary)700 |
ChildOf | Category | 381 | J2EE Time and State Issues | Development Concepts (primary)699 |
ChildOf | Category | 634 | Weaknesses that Affect System Processes | Resource-specific Weaknesses (primary)631 |
ChildOf | Weakness Base | 695 | Use of Low-Level Functionality | Research Concepts (primary)1000 |
ParentOf | Weakness Variant | 543 | Use of Singleton Pattern in a Non-thread-safe Manner | Development Concepts (primary)699 |
Mapped Taxonomy Name | Node ID | Fit | Mapped Node Name |
---|---|---|---|
7 Pernicious Kingdoms | J2EE Bad Practices: Threads |
Submissions | ||||
---|---|---|---|---|
Submission Date | Submitter | Organization | Source | |
7 Pernicious Kingdoms | Externally Mined | |||
Modifications | ||||
Modification Date | Modifier | Organization | Source | |
2008-07-01 | Sean Eidemiller | Cigital | External | |
added/updated demonstrative examples | ||||
2008-07-01 | Eric Dalci | Cigital | External | |
updated Time of Introduction | ||||
2008-09-08 | CWE Content Team | MITRE | Internal | |
updated Relationships, Other Notes, Taxonomy Mappings | ||||
Previous Entry Names | ||||
Change Date | Previous Entry Name | |||
2008-01-30 | J2EE Bad Practices: Threads | |||
2008-04-11 | J2EE Bad Practices: Use of Threads | |||