Wednesday, April 17, 2019


package com.example.demo;

import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;

public class DemoApplication implements CommandLineRunner {

    public static void main(String[] args) {, args);

    public void run(String... args) throws Exception {
        CompletableFuture<String> completableFuture = new CompletableFuture<String>();
        completableFuture.complete("Future's Result");

        String result = completableFuture.get();

        CompletableFuture<Void> future = CompletableFuture.runAsync(new Runnable() {
            public void run() {
                // Simulate a long-running Job
                try {
                } catch (InterruptedException e) {
                    throw new IllegalStateException(e);
                System.out.println("I'll run in a separate thread than the main thread.");
        // Block and wait for the future to complete


No comments: