-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathThreadTest.java
More file actions
42 lines (33 loc) · 824 Bytes
/
ThreadTest.java
File metadata and controls
42 lines (33 loc) · 824 Bytes
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
package concurrent.thread;
/**
* Created by Edwin Xu on 6/28/2020 4:09 PM
*/
public class ThreadTest implements Runnable{
private String name;
private int cnt = 0;
public ThreadTest(String name){
this.name=name;
}
@Override
public void run() {
while (true){
System.out.println(name+" :"+cnt);
cnt++;
Thread.yield();
try {
if (cnt>100){
// cnt=1;
this.wait();
}
}catch (Exception e){
}
}
}
public static void main(String[] args) {
Thread t1 = new Thread( new ThreadTest("Father"));
ThreadTest t2 = new ThreadTest("Son_SamePkg");
t1.run();
t2.run();
// t1.notifyAll();
}
}