-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGetPriority.java
More file actions
44 lines (36 loc) · 1 KB
/
Copy pathGetPriority.java
File metadata and controls
44 lines (36 loc) · 1 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
package threadbook.ch06;
public class GetPriority extends Object {
private static Runnable makeRunnable() {
Runnable r = new Runnable() {
public void run() {
for ( int i = 0; i < 5; i++ ) {
Thread t = Thread.currentThread();
System.out.println(
"in run() - priority=" +
t.getPriority() +
", name=" + t.getName());
try {
Thread.sleep(2000);
} catch ( InterruptedException x ) {
// ignore
}
}
}
};
return r;
}
public static void main(String[] args) {
System.out.println(
"in main() - Thread.currentThread().getPriority()=" +
Thread.currentThread().getPriority());
System.out.println(
"in main() - Thread.currentThread().getName()=" +
Thread.currentThread().getName());
Thread threadA = new Thread(makeRunnable(), "threadA");
threadA.start();
try { Thread.sleep(3000); }
catch ( InterruptedException x ) { }
System.out.println("in main() - threadA.getPriority()=" +
threadA.getPriority());
}
}