-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEventClient.java
More file actions
37 lines (34 loc) · 991 Bytes
/
EventClient.java
File metadata and controls
37 lines (34 loc) · 991 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
package chapter05;
import java.util.concurrent.TimeUnit;
/**
* Created by zhangzhao on 2018/8/23.
*/
public class EventClient {
public static void main(String[] args){
final EventQueue eventQueue = new EventQueue();
new Thread(()->
{
for(;;){
eventQueue.offer(new EventQueue.Event());
try {
TimeUnit.SECONDS.sleep(1);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
,"Producer").start();
new Thread(()->
{
for(;;){
eventQueue.take();
try {
TimeUnit.SECONDS.sleep(10);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
,"Consumer").start();
}
}