question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Behaviour of methods returning CompletionStage with and without @Asynchronous

See original GitHub issue

It is not clear what’s the difference, in the expected behavior, when returning a CompletableFuture from a method annotated with @Asynchronous and from a method without that annotation. Examples:

    import org.eclipse.microprofile.faulttolerance.Asynchronous;

    @Asynchronous
    public CompletionStage<String> serviceA() {
        CompletableFuture<String> future = new CompletableFuture<>();
        ...
        return future;
    }
    public CompletionStage<String> serviceA() {
        CompletableFuture<String> future = new CompletableFuture<>();
        ...
        return future;
    }

This is especially important when we are using the @Retry annotation in the methods. What will happen when a retry is performed in both serviceA() and serviceB()?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
Emily-Jiangcommented, Dec 12, 2018

Method without @Asynchronous annotation returning CompletionStage will not be retried even if Retry annotation is specified and the completionStage is completed exceptionally, which is the previous behaviour.

@Retry
public CompletionStage<String> serviceA() {
        CompletableFuture<String> future = new CompletableFuture<>();
        ...
        return future;
    }

In the above method, the serviceA returned exceptionally will not be retried.

0reactions
Emily-Jiangcommented, Dec 19, 2018

@brunobat @carlosdlr @Azquelt agreed the above statement on 19th Dec.

Read more comments on GitHub >

github_iconTop Results From Across the Web

CompletableFuture practical guide | by Yurko - Medium
A Future represents the pending result of an asynchronous computation. And CompletionStage is a promise. Promise that computation will be done ...
Read more >
java - How to return CompletionStage<Response> both ...
You can create and return a completed CompletableFuture , which implements the CompletionStage using the CompletableFuture. completedFuture ...
Read more >
Write Clean Asynchronous Code With CompletableFuture ...
Assume we want to find firstName of five different users and combine the results.The CompletableFuture.allOf static method allows to wait for ...
Read more >
20 Practical Examples: Java's CompletableFuture - DZone
A CompletableFuture is executed asynchronously when the method typically ends with the keyword Async; By default (when no Executor is ...
Read more >
CompletableFuture (Java Platform SE 8 ) - Oracle Help Center
Returns a new CompletionStage that, when either this or the other given stage complete normally, is executed using this stage's default asynchronous execution ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found