forked from brianway/java-learning
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRun6_hasQueueThread.java
More file actions
43 lines (36 loc) · 1.04 KB
/
Copy pathRun6_hasQueueThread.java
File metadata and controls
43 lines (36 loc) · 1.04 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
package com.brianway.learning.java.multithread.lock.example6;
/**
* Created by Brian on 2016/4/15.
*/
/**
* P222
* 测试方法boolean hasQueueThread(Thread thread)
* 查询指定的线程是否正在等待获取此锁定
* 测试方法boolean hasQueueThreads()
* 查询是否有线程正在等待获取此锁定
*/
public class Run6_hasQueueThread {
public static void main(String[] args) throws InterruptedException {
final Service1 service = new Service1();
Runnable runnable = new Runnable() {
public void run() {
service.waitMethod();
}
};
Thread threadA = new Thread(runnable);
threadA.start();
Thread.sleep(500);
Thread threadB = new Thread(runnable);
threadB.start();
Thread.sleep(500);
System.out.println(service.lock.hasQueuedThread(threadA));
System.out.println(service.lock.hasQueuedThread(threadB));
System.out.println(service.lock.hasQueuedThreads());
}
}
/*
输出:
false
true
true
*/