-
Notifications
You must be signed in to change notification settings - Fork 267
Expand file tree
/
Copy pathLockSupportBlockerTest.java
More file actions
30 lines (27 loc) · 1.09 KB
/
Copy pathLockSupportBlockerTest.java
File metadata and controls
30 lines (27 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
package com.javaedge.concurrency;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.LockSupport;
public class LockSupportBlockerTest {
public static void main(String[] args) {
Thread t3 = new Thread(() -> {
Thread.currentThread().setName("t3");
System.out.println(Thread.currentThread().getName() + " park 5 seconds");
//park 5 seconds, set blocker
Object blocker = new String("JavaEdge");
LockSupport.parkUntil(blocker, System.currentTimeMillis() + TimeUnit.MILLISECONDS.convert(5, TimeUnit.SECONDS));
System.out.println(Thread.currentThread().getName() + " after park");
});
t3.start();
try {
Object t3_blocker = null;
while (t3_blocker == null) {
t3_blocker = LockSupport.getBlocker(t3);
TimeUnit.MILLISECONDS.sleep(10);
}
System.out.println("t3 blocker is :" + t3_blocker);
t3.join();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}