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?

A Java Future, java.util.concurrent.Future, represents the result of an asynchronous computation. When the asynchronous task is created, a Java Future object is returned. This Future object functions as a handle to the result of the asynchronous task. Once the asynchronous task completes, the result can be accessed via the Future object returned when the task was started

source: http://tutorials.jenkov.com/java-util-concurrent/java-future.html


CompletableFuture (Java8+)

...

Code Block
languagejava
themeEclipse
titleSimple Future Example
collapsetrue
publicCompletableFuture<Void> future Future<String> calculateAsync= CompletableFuture.runAsync(() throws-> InterruptedException {
    CompletableFuture<String> completableFuture = new CompletableFuture<>();
// Simulate a long-running Job   
    Executors.newCachedThreadPool().submit(() ->try {
        ThreadTimeUnit.SECONDS.sleep(5001);
    } catch (InterruptedException  completableFuture.complete("Hello");
e) {
        throw return nullnew IllegalStateException(e);
    });

    return completableFuture;
}
    System.out.println("I'll run in a separate thread than the main thread.");
});

source: https://www.baeldungcallicoder.com/java-8-completablefuture-tutorial/

Alternatives

Thread

Code Block
languagejava
titleThread Example
collapsetrue
int number = 20;
Thread newThread = new Thread(() -> {
    System.out.println("Factorial of " + number + " is: " + factorial(number));
});
newThread.start();

...

#TypeProsConsRecommend
1FutureFutures return value
Y
2Thread
threads does not return anything as the run() method returns void. We could possibly implement mechanism to trigger a response but this is unnecessary as futures do thisN

RequestID Generation

...

TypeMethodEase of implementationRecommend
UUID
String uniqueID = UUID.randomUUID().toString();
EasyY
CustomWe generate our ownMedium - HardN

...

Async Request Option using Messaging

...


Demo/Test

...

Jira
serverONAP Jira
serverId425b2b0a-557c-3c0c-b515-579789cceedb
keyCPS-834