You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: java/ql/src/Likely Bugs/Concurrency/CallsToRunnableRun.qhelp
+11-9
Original file line number
Diff line number
Diff line change
@@ -7,37 +7,37 @@
7
7
<overview>
8
8
<p>A direct call of a <code>Thread</code> object's <code>run</code> method
9
9
does not start a separate thread. The method is executed within the current thread.
10
-
This is an unusual use because <code>Thread.run()</code> is normally
11
-
intended to be called from within a separate thread.
10
+
This is an unusual use because <code>Thread.run()</code> is normally
11
+
intended to be called from within a separate thread.
12
12
</p>
13
13
14
14
</overview>
15
15
<recommendation>
16
16
17
-
<p>To execute <code>Runnable.run</code> from within a separate thread, do one of the
17
+
<p>To execute <code>Runnable.run</code> from within a separate thread, do one of the
18
18
following:</p>
19
19
20
20
<ul>
21
-
<li>Construct a <code>Thread</code> object using the <code>Runnable</code> object, and call
21
+
<li>Construct a <code>Thread</code> object using the <code>Runnable</code> object, and call
22
22
<code>start</code> on the <code>Thread</code> object.</li>
23
-
<li>Define a subclass of a <code>Thread</code> object, and override the definition of its
23
+
<li>Define a subclass of a <code>Thread</code> object, and override the definition of its
24
24
<code>run</code> method. Then construct an instance of this subclass and call <code>start</code>
25
25
on that instance directly.</li>
26
26
</ul>
27
27
28
28
</recommendation>
29
29
<example>
30
30
31
-
<p>In the following example, the main thread, <code>ThreadDemo</code>, calls the child thread,
31
+
<p>In the following example, the main thread, <code>ThreadDemo</code>, calls the child thread,
32
32
<code>NewThread</code>, using <code>run</code>. This causes the child thread to run to
33
-
completion before the rest of the main thread is executed, so that "Child thread activity" is
33
+
completion before the rest of the main thread is executed, so that "Child thread activity" is
34
34
printed before "Main thread activity".</p>
35
35
36
36
<samplesrc="CallsToRunnableRun.java" />
37
37
38
-
<p>To enable the two threads to run concurrently, create the child thread and call
38
+
<p>To enable the two threads to run concurrently, create the child thread and call
39
39
<code>start</code>, as shown below. This causes the main thread to
40
-
continue while the child thread is waiting, so that "Main thread activity" is printed before
40
+
continue while the child thread is waiting, so that "Main thread activity" is printed before
41
41
"Child thread activity".</p>
42
42
43
43
<samplesrc="CallsToRunnableRunFixed.java" />
@@ -48,6 +48,8 @@ continue while the child thread is waiting, so that "Main thread activity" is pr
48
48
49
49
<li>
50
50
The Java Tutorials: <ahref="https://docs.oracle.com/javase/tutorial/essential/concurrency/runthread.html">Defining and Starting a Thread</a>.
51
+
Java API Specification: <ahref="https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/Thread.html#run()">Thread.run()</a>.
52
+
SEI CERT Oracle Coding Standard for Java: <ahref="https://wiki.sei.cmu.edu/confluence/display/java/THI00-J.+Do+not+invoke+Thread.run()">THI00-J. Do not invoke Thread.run()</a>.
0 commit comments