-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStateDemo.java
More file actions
51 lines (39 loc) · 1.03 KB
/
StateDemo.java
File metadata and controls
51 lines (39 loc) · 1.03 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
47
48
49
50
51
package multithread;
import java.io.IOException;
/**
* @author zhongshanhuang
* @company caih
* @email [email protected]
* @create 2019-10-19 15:04
*/
public class StateDemo {
public static void main(String[] args) throws InterruptedException {
// //1,运行
// Thread thread = new Thread(() -> {
// try {
// System.in.read();
// } catch (IOException e) {
// e.printStackTrace();
// }
// });
//
// thread.run();
//超时等待,阻塞
Object obj = new Object();
Thread thread1 = new Thread(() -> {
synchronized(obj){
try {
Thread.sleep(10000000L);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
});
thread1.start();
Thread.sleep(1000L);
Thread thread2 = new Thread(() -> {
synchronized(obj){}
});
thread2.start();
}
}