1 |
|
class Consumer extends Thread { |
2 |
|
|
3 |
< |
public Consumer(Queue queue) { |
3 |
> |
public Consumer(Queue queue, long sleepTime) { |
4 |
|
_queue = queue; |
5 |
+ |
_sleepTime = sleepTime; |
6 |
|
} |
7 |
|
|
8 |
|
public void run() { |
9 |
< |
while(true) { |
10 |
< |
try { Thread.sleep(1000); } catch(Exception e) {} |
11 |
< |
String s = (String) _queue.get(); |
12 |
< |
System.out.println(s); |
9 |
> |
boolean run; |
10 |
> |
try { |
11 |
> |
_n = _queue.getQueue(); |
12 |
> |
System.out.println("Got queue: "+_n); |
13 |
> |
run = true; |
14 |
|
} |
15 |
+ |
catch(NoQueueException e) { |
16 |
+ |
System.out.println("Failed to get a Queue:"); |
17 |
+ |
System.out.println(e); |
18 |
+ |
run=false; |
19 |
+ |
} |
20 |
+ |
while(run) { |
21 |
+ |
try { Thread.sleep(_sleepTime); } catch(Exception e) {} |
22 |
+ |
String s = (String) _queue.get(_n); |
23 |
+ |
System.out.println("["+_n+"] "+s); |
24 |
+ |
} |
25 |
|
} |
26 |
|
|
27 |
|
private Queue _queue; |
28 |
+ |
private int _n; |
29 |
+ |
private long _sleepTime; |
30 |
|
|
31 |
|
} |