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

Sign up
Appearance settings

Commit ea4b7c7

Browse files
Create LockSupportBlockerTest.java
1 parent 55ea7b6 commit ea4b7c7

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
public class LockSupportBlockerTest {
2+
public static void main(String[] args) {
3+
Thread t3 = new Thread(() -> {
4+
Thread.currentThread().setName("t3");
5+
System.out.println(Thread.currentThread().getName() + " park 5 seconds");
6+
//park 5 seconds, set blocker
7+
Object blocker = new String("sss");
8+
LockSupport.parkUntil(blocker, System.currentTimeMillis() + TimeUnit.MILLISECONDS.convert(5, TimeUnit.SECONDS));
9+
System.out.println(Thread.currentThread().getName() + " after park");
10+
});
11+
t3.start();
12+
13+
try {
14+
Object t3_blocker = null;
15+
while (t3_blocker == null) {
16+
t3_blocker = LockSupport.getBlocker(t3);
17+
TimeUnit.MILLISECONDS.sleep(10);
18+
}
19+
System.out.println("t3 blocker is :" + t3_blocker);
20+
t3.join();
21+
} catch (InterruptedException e) {
22+
e.printStackTrace();
23+
}
24+
}
25+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /