1CompletableFuture<Long> completableFuture = CompletableFuture.supplyAsync(() -> factorial(number));
2while (!completableFuture.isDone()) {
3 System.out.println("CompletableFuture is not finished yet...");
4}
5long result = completableFuture.get();
6
1ExecutorService threadpool = Executors.newCachedThreadPool();
2Future<Long> futureTask = threadpool.submit(() -> factorial(number));
3
4while (!futureTask.isDone()) {
5 System.out.println("FutureTask is not finished yet...");
6}
7long result = futureTask.get();
8
9threadpool.shutdown();
10
1int number = 20;
2Thread newThread = new Thread(() -> {
3 System.out.println("Factorial of " + number + " is: " + factorial(number));
4});
5newThread.start();
6