FileDocCategorySizeDatePackage
CalculatorTest.javaAPI DocExample676Mon Mar 08 22:41:36 GMT 2004javathreads.examples.ch05.example4

CalculatorTest.java

package javathreads.examples.ch05.example4;

public class CalculatorTest extends Calculator implements Runnable {

    public static void main(String[] args) {
        int nThreads = Integer.parseInt(args[0]);
        for (int i = 0; i < nThreads; i++) {
            Thread t = new Thread(new CalculatorTest());
            t.start();
        }
    }

    public void run() {
        for (int i = 0; i < 30; i++) {
            Integer p = new Integer(i % 5);
            calculate(p);
        }
    }

    protected Object doLocalCalculate(Object p) {
        System.out.println("Doing calculation of " + p + " in thread " + Thread.currentThread());
        return p;
    }
}