Consumerpublic class Consumer extends Worker This class pulls WorkUnit instances from a Queue
and performs a certain amount of "work", specified
by workFactor.
This class is identical to smaple.standard.Consumer.
We could have used that class in our example. However,
it has been copied into the dynamic package so that it
may inherit from dynamic.Basic instead of sample.standard.Basic. |
Fields Summary |
---|
public static final String | ROLE | private static final int | DEFAULT_WORK_FACTOR |
Constructors Summary |
---|
public Consumer(Queue queue)
this(queue, DEFAULT_WORK_FACTOR);
| public Consumer(Queue inputQueue, int workFactor)
super(inputQueue, workFactor);
|
Methods Summary |
---|
public void | run()
//**********
// This is where the "work" takes place. In a real-world
/// application that uses this pattern, this logic would
/// be replaced by the real application logic.
//**********
_queue.addConsumer();
while (!_stopCalled) {
while (_suspended) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {}
}
WorkUnit unit = (WorkUnit)_queue.remove();
// Burn some cycles...
calculatePrimes(_workFactor);
_numberOfUnitsProcessed++;
}
_queue.removeConsumer();
|
|