28 lines
741 B
Plaintext
28 lines
741 B
Plaintext
![]() |
The purpose of the <code>Thread.run()</code> method is to execute code in a separate, dedicated thread. Calling this method directly doesn't make sense because it causes its code to be executed in the current thread.
|
||
|
|
||
|
To get the expected behavior, call the <code>Thread.start()</code> method instead.
|
||
|
|
||
|
|
||
|
== Noncompliant Code Example
|
||
|
|
||
|
----
|
||
|
Thread myThread = new Thread(runnable);
|
||
|
myThread.run(); // Noncompliant
|
||
|
----
|
||
|
|
||
|
|
||
|
== Compliant Solution
|
||
|
|
||
|
----
|
||
|
Thread myThread = new Thread(runnable);
|
||
|
myThread.start(); // Compliant
|
||
|
----
|
||
|
|
||
|
|
||
|
== See
|
||
|
|
||
|
* http://cwe.mitre.org/data/definitions/572.html[MITRE, CWE-572] - Call to Thread run() instead of start()
|
||
|
* https://www.securecoding.cert.org/confluence/x/KQAiAg[CERT THI00-J.] - Do not invoke Thread.run()
|
||
|
|
||
|
|