public static void main(String[] args) {
		ThreadPoolExecutor executor = (ThreadPoolExecutor) Executors
				.newFixedThreadPool(2);
		List<Future<Integer>> resultList = new ArrayList<>();

		Random random = new Random();
		// generate 10 random number
		for (int i = 0; i < 10; i++) {
			Integer number = random.nextInt(10);
			FactorialCalculator caculator = new FactorialCalculator(number);
			Future<Integer> result = executor.submit(caculator);
			resultList.add(result);
		}

		// wait until all tasks finished
		do {
			System.out.printf("Main: number of completed tasks is %d\n",
					executor.getCompletedTaskCount());
			for (int i = 0; i < resultList.size(); i++) {
				Future<Integer> result = resultList.get(i);
				System.out.printf("Main: task-%d is done? %s\n", i,
						result.isDone());
			}
			try {
				TimeUnit.MILLISECONDS.sleep(50);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		} while (executor.getCompletedTaskCount() < resultList.size());

		// print out all results
		System.out.println("Main: Results");
		for (int i = 0; i < resultList.size(); i++) {
			Future<Integer> result = resultList.get(i);

			Integer number = null;
			try {
				number = result.get();
			} catch (InterruptedException | ExecutionException e) {
				e.printStackTrace();
			}
			System.out.printf("Main: Task-%d result is %d\n", i, number);
		}

		executor.shutdown();

	}