Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Will we be able to handle everything "as-is"?

Future or alternative

...

What are Futures?



CompletableFuture (Java8+)

Java 8 introduced the CompletableFuture class. Along with the Future interface, it also implemented the CompletionStage interface. This interface defines the contract for an asynchronous computation step that we can combine with other steps.

CompletableFuture is at the same time a building block and a framework, with about 50 different methods for composing, combining, and executing asynchronous computation steps and handling errors.


Code Block
languagejava
titleSimple Future Example
collapsetrue
public Future<String> calculateAsync() throws InterruptedException {
    CompletableFuture<String> completableFuture = new CompletableFuture<>();

    Executors.newCachedThreadPool().submit(() -> {
        Thread.sleep(500);
        completableFuture.complete("Hello");
        return null;
    });

    return completableFuture;
}

source: https://www.baeldung.com/java-completablefuture

RequestID Generation

TypeMethod
UUID
String uniqueID = UUID.randomUUID().toString();

...