1 |
tdb |
1.1 |
class Producer extends Thread { |
2 |
|
|
|
3 |
tdb |
1.2 |
public Producer(Queue queue, long sleepTime) { |
4 |
tdb |
1.1 |
_queue = queue; |
5 |
tdb |
1.2 |
_sleepTime = sleepTime; |
6 |
tdb |
1.1 |
} |
7 |
|
|
|
8 |
|
|
public void run() { |
9 |
|
|
int count = 0; |
10 |
|
|
while(true) { |
11 |
tdb |
1.2 |
try { Thread.sleep(_sleepTime); } catch(Exception e) {} |
12 |
tdb |
1.1 |
_queue.add("Object number "+count); |
13 |
|
|
count ++; |
14 |
|
|
if(count % 10 == 0) { |
15 |
|
|
System.out.println(_queue.status()); |
16 |
|
|
} |
17 |
|
|
} |
18 |
|
|
} |
19 |
|
|
|
20 |
|
|
private Queue _queue; |
21 |
tdb |
1.2 |
private long _sleepTime; |
22 |
tdb |
1.1 |
|
23 |
|
|
} |