-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathPriorityCalls.qhelp
More file actions
46 lines (34 loc) · 1.26 KB
/
PriorityCalls.qhelp
File metadata and controls
46 lines (34 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<!DOCTYPE qhelp PUBLIC
"-//Semmle//qhelp//EN"
"qhelp.dtd">
<qhelp>
<overview>
<p>Specifying thread priorities using calls to <code>Thread.setPriority</code>
and <code>Thread.getPriority</code> is not portable
and may have adverse consequences such as starvation.
</p>
</overview>
<recommendation>
<p>Avoid setting thread priorities to control interactions between threads.
Using the default thread priority should be sufficient for most applications.
</p>
<p>However, if you need to enforce a specific synchronization order, use one of the following
alternatives:</p>
<ul>
<li>Waiting for a notification using the <code>wait</code> and <code>notifyAll</code> methods</li>
<li>Using the <code>java.util.concurrent</code> library</li>
</ul>
<p>In some cases, calls to <code>Thread.sleep</code> may be appropriate to temporarily stop
execution (provided that there is no possibility for race conditions), but this is not generally
recommended.</p>
</recommendation>
<references>
<li>
J. Bloch, <em>Effective Java (second edition)</em>, Item 72. Addison-Wesley, 2008.
</li>
<li>
Inform IT:
<a href="http://www.informit.com/articles/article.aspx?p=26326&seqNum=5">Adding Multithreading Capability to Your Java Applications</a>.
</li>
</references>
</qhelp>