// Project: Multithreading // Source code file: Adder.java // Show how to use threads to add numbers in parallel. // A class that implements Runnable can be run in a thread. public class Adder implements Runnable { private int total, start, end; public Adder(int start, int end) { this.start = start; this.end = end; } public int getTotal( ) { return this.total; } // Required method for Runnable interface. @Override public void run( ) { int sum = 0; for (int i = this.start; i < this.end; i++) { sum += i; } this.total = sum; System.out.println("Start: " + this.start + " End: " + this.end + " Total: " + this.total); } }