Skip to content

Commit 67b93dd

Browse files
Jami CogswellJami Cogswell
Jami Cogswell
authored and
Jami Cogswell
committed
Java: add more qhelp references and add 'override' to example
1 parent 4b933b0 commit 67b93dd

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

java/ql/src/Likely Bugs/Concurrency/CallsToRunnableRun.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ public static void main(String args[]) {
99
}
1010

1111
class NewThread extends Thread {
12+
@Override
1213
public void run() {
1314
try {
1415
Thread.sleep(10000);
@@ -18,4 +19,4 @@ public void run() {
1819
}
1920
System.out.println("Child thread activity.");
2021
}
21-
}
22+
}

java/ql/src/Likely Bugs/Concurrency/CallsToRunnableRun.qhelp

+11-9
Original file line numberDiff line numberDiff line change
@@ -7,37 +7,37 @@
77
<overview>
88
<p>A direct call of a <code>Thread</code> object's <code>run</code> method
99
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.
1212
</p>
1313

1414
</overview>
1515
<recommendation>
1616

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
1818
following:</p>
1919

2020
<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
2222
<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
2424
<code>run</code> method. Then construct an instance of this subclass and call <code>start</code>
2525
on that instance directly.</li>
2626
</ul>
2727

2828
</recommendation>
2929
<example>
3030

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,
3232
<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
3434
printed before "Main thread activity".</p>
3535

3636
<sample src="CallsToRunnableRun.java" />
3737

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
3939
<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
4141
"Child thread activity".</p>
4242

4343
<sample src="CallsToRunnableRunFixed.java" />
@@ -48,6 +48,8 @@ continue while the child thread is waiting, so that "Main thread activity" is pr
4848

4949
<li>
5050
The Java Tutorials: <a href="https://docs.oracle.com/javase/tutorial/essential/concurrency/runthread.html">Defining and Starting a Thread</a>.
51+
Java API Specification: <a href="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: <a href="https://wiki.sei.cmu.edu/confluence/display/java/THI00-J.+Do+not+invoke+Thread.run()">THI00-J. Do not invoke Thread.run()</a>.
5153
</li>
5254

5355

0 commit comments

Comments
 (0)