FileDocCategorySizeDatePackage
FibonacciConsumer.javaAPI DocExample779Sat Apr 17 23:40:44 BST 2004javathreads.examples.ch08.example6

FibonacciConsumer

public class FibonacciConsumer extends Object implements Runnable

Fields Summary
private Fibonacci
fib
private Thread
thr
private BlockingQueue
queue
Constructors Summary
public FibonacciConsumer(BlockingQueue q)


       
        queue = q;
        thr = new Thread(this);
        thr.start();
    
Methods Summary
public voidrun()

        int request, result;
        try {
            while (true) {
                request = queue.take().intValue();
                result = fib.calculateWithCache(request);
                System.out.println("Calculated result of " + result + " from " + request);
            }
        } catch (InterruptedException ex) {

        }