import java.util.concurrent.*; class Summation implements Callable { private int upper; public Summation(int upper) { this.upper = upper; } /* The thread will execute in this method */ public Integer call() { int sum = 0; for (int i = 1; i <= upper; i++) { sum += i; System.out.println ("upper="+upper+", i:"+i); } return sum; } } public class ThreadDriver { public static void main(String[] args) { int upper = Integer.parseInt(args[0]); ExecutorService pool = Executors.newSingleThreadExecutor(); Future result = pool.submit(new Summation(upper)); Future result1 = pool.submit(new Summation(upper*2)); try { System.out.println("sum = " + result.get()); System.out.println("sum1 = " + result1.get()); } catch (InterruptedException | ExecutionException ie) { } } }