-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestBlockingQueue.java
More file actions
49 lines (44 loc) · 1012 Bytes
/
TestBlockingQueue.java
File metadata and controls
49 lines (44 loc) · 1012 Bytes
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
import java.net.Socket;
import java.util.TreeMap;
public class TestBlockingQueue {
/**
* @param args
*/
public static void main(String[] args) {
final ConcurrentBlockingQueue<BeanTest> cache = new ConcurrentBlockingQueue<BeanTest>(
100000);
new Thread() {
public void run() {
int a = 0;
while (true) {
cache.put(new BeanTest("test"+a));
a++;
// if(a == 1000){
// break;
// }
}
}
}.start();
new Thread() {
long start = System.currentTimeMillis();
long count = 0;
long temp = 0;
public void run() {
BeanTest bean = null;
while (true) {
bean = cache.take();
temp++;
long end = System.currentTimeMillis();
if (end - start >= 1000) {
System.out.println(Thread.currentThread());
start = end;
System.out.println(temp - count);
count = temp;
System.out.println(bean);
}
// System.out.println(temp);
}
}
}.start();
}
}