-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathLockSupportIntDemo.java
More file actions
41 lines (34 loc) · 1.09 KB
/
LockSupportIntDemo.java
File metadata and controls
41 lines (34 loc) · 1.09 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
package PracticeJavaHighConcurrency.chapter3;
import java.util.concurrent.locks.LockSupport;
/**
* Created by 13 on 2017/5/5.
*/
public class LockSupportIntDemo {
public static Object u = new Object();
static ChangeObjectThread t1 = new ChangeObjectThread("t1");
static ChangeObjectThread t2 = new ChangeObjectThread("t2");
public static class ChangeObjectThread extends Thread {
public ChangeObjectThread(String name) {
super.setName(name);
}
public void run() {
synchronized (u) {
System.out.println("in " + getName());
LockSupport.park();
if (Thread.interrupted()) {
}
System.out.println(getName() + " Interrupted");
}
System.out.println(getName() + " Continue Run");
}
}
public static void main(String args[]) throws InterruptedException {
t1.start();
Thread.sleep(100);
t2.start();
LockSupport.unpark(t1);
LockSupport.unpark(t2);
t1.join();
t2.join();
}
}