package jvm.createthread;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;

public class CreateByCompletableFuture {

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        CompletableFuture<String> cf = CompletableFuture.supplyAsync(() -> {
            System.out.println("create thread by using CompletableFuture. Returning results...");
            return "hello!";
        });

        while (true) {
            if (cf.isDone()) {
                System.out.println(cf.get());
                break;
            }
        }

//        try {
//            Thread.sleep(0);
//            System.out.println(cf.get());
//        } catch (InterruptedException e) {
//            e.printStackTrace();
//        } catch (ExecutionException e) {
//            throw new RuntimeException(e);
//        }
    }
}
