FileDocCategorySizeDatePackage
Task.javaAPI DocExample932Sat Jul 31 20:23:50 BST 2004javathreads.examples.ch09

Task

public class Task extends Object implements Runnable

Fields Summary
long
n
String
id
Constructors Summary
public Task(long n, String id)

        this.n = n;
        this.id = id;
    
Methods Summary
private longfib(long n)

        if (n == 0)
            return 0L;
        if (n == 1)
            return 1L;
        return fib(n - 1) + fib(n - 2);
    
public voidrun()

        Date d = new Date();
        DateFormat df = new SimpleDateFormat("HH:mm:ss:SSS");
        long startTime = System.currentTimeMillis();
        d.setTime(startTime);
        System.out.println("Starting task " + id + " at " + df.format(d));
        fib(n);
        long endTime = System.currentTimeMillis();
        d.setTime(endTime);
        System.out.println("Ending task " + id + " at " + df.format(d) + " after " + (endTime - startTime) + " milliseconds");