Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
executable file
·
105 lines (82 loc) · 2.92 KB

File metadata and controls

executable file
·
105 lines (82 loc) · 2.92 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package thread;
/**
* 测试线程优先级,只有大概的总结。不能严格依靠线程来制定优先级
*/
public class TestPriorityState {
public static void main(String[] args) {
//testState();
testPriority();
}
/**
* 测试thread的优先级
*/
static void testPriority() {
for (int i = 1; i < 11; i++) {
final int j = i;
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
System.out.println("run1 " + j);
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("run2 " + j);
}
});
thread.setPriority(i);
thread.start();
}
}
/**
* 测试thread的状态
*/
static void testState() {
final Thread mThread = new Thread(new Runnable() {
@Override
public void run() {
for (int i = 0; i < 5; i++) {
try {
System.out.println("不要搞事情啊");
Thread.sleep(10);
for (int j = 0; j < 10000000; j++) {
String s = "" + j;
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
});
mThread.start();
new Thread(new Runnable() {
@Override
public void run() {
for (int i = 0; i < 8; i++) {
if (mThread.getState() == Thread.State.NEW) {
System.out.println("new");
} else if (mThread.getState() == Thread.State.RUNNABLE) {
System.out.println("RUNNABLE");
} else if (mThread.getState() == Thread.State.BLOCKED) {
System.out.println("BLOCKED");
} else if (mThread.getState() == Thread.State.TERMINATED) {
System.out.println("TERMINATED");
} else if (mThread.getState() == Thread.State.WAITING) {
System.out.println("WAITING");
} else if (mThread.getState() == Thread.State.TIMED_WAITING) {
System.out.println("TIMED_WAITING");
} else {
System.out.println("其它状态");
}
try {
Thread.sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}).start();
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.