Questions tagged [completion-stage]

Java 8 common API interface of a possibly asynchronous computation, that performs an action or computes a value when another CompletionStage completes. Note: this tag is a bit different from `completable-future`, which is a default implementation of this CompletionStage API

Java 8 common API interface of a possibly asynchronous computation, that performs an action or computes a value when another CompletionStage completes:

https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/CompletionStage.html

40 questions
5
votes
1 answer

How to nicely do allOf/AnyOf with Collections of CompletionStage

Currently to do something simple with Collections of CompletionStage requires jumping through several ugly hoops: public static CompletionStage translate(String foo) { // just example code to reproduce return…
tkruse
  • 10,222
  • 7
  • 53
  • 80
4
votes
1 answer

How to force CompletableFuture.thenApply() to run on the same thread that ran the previous stage?

Here's a short code version of the problem I'm facing: public static void main(String[] args) { CompletableFuture.supplyAsync(() -> { /* try { Thread.sleep(2000); } catch…
4
votes
2 answers

How to combine multiple CompletionStage responses of type List(for me) or some other in java

I am trying to create multiple CompletionStage of type List, eg. CompletionStage>. And at the end I want to merge all the responses of type > in to one List in one CompletionStage. CompletionStage> completionStageOne=…
user2367130
  • 125
  • 1
  • 2
  • 10
3
votes
1 answer

Why thenCombine result doesn't complete exceptionally if returning a failed stage?

The following code snippet, which invokes thenCombine, does not set an exception at whenComplete (it prints No exception): CompletableFuture.completedFuture(true) .thenCombine(CompletableFuture.completedFuture(true), (x,y) -> { …
3
votes
2 answers

How to combine Source.repeat and Source.completionStage using Akka

I'm using akka with a microservice framework, so I've got a lot of completionStage requests. I want to get a list of elements from one microservice and zip them together with a single element from another such that I end up with a Source of…
Simon
  • 69
  • 1
  • 6
3
votes
1 answer

Concurrently run a Void CompletionStage but ignore result

I have two completionStages method calls that each call a remote service if a condition is not met. They are both pretty long running processes and we need to decrease latency. I also do not care for the secondFuture's response. It could return…
sizzle
  • 2,883
  • 2
  • 13
  • 10
3
votes
2 answers

(Datastax 4.1.0) (Cassandra )How do I collect all responses with session.executeAsync?

I wantta make async call to cassandra db with execute.Async call in manuel I found this code but I couldn't understand how to collect all rows into any list. Really basic call like Select * from table, and I want to store all the…
3
votes
0 answers

What is "this stage's default asynchronous execution facility"? (Java CompletionStage/CompletableFuture)

In Oracle Java documentation for CompletionStage and ComletableFuture all *Async methods without an explicit Executor argument refer to some stage's default asynchronous execution facility executes the given action using this stage's default…
2
votes
2 answers

Is there a converter from List to CompletionStage in Java?

Like in this hypothetical example of using of: List> listOfFutureLongs = getFutureLongs(...) CompletionStage> futureListOfLongs = CompletionStage.of(listOfFutureLongs)
Michael M.
  • 467
  • 3
  • 10
2
votes
1 answer

using CompletionStage instead of CompletableFuture

given the following method: private static String getChuckNorrisJoke () { try { HttpURLConnection con = (HttpURLConnection) new URL( "http://api.icndb.com/jokes/random" ).openConnection(); BufferedReader in = new…
1
vote
2 answers

Difference between completeExceptionally and obtrudeException

Just going through the CompletableFuture documentation and stumbled upon the completeExceptionally and obtrudeException methods and is having a hard time comprehending the difference and use case. Can the community help understand the difference and…
1
vote
0 answers

How to nest CompleteFuture timeouts

What I am trying to do: Background: Latency is critical. I have 2 methods that return basically the same information, but will execute differently. One will be on average faster, but may by chance sometimes be slower. The second is on average…
1
vote
0 answers

CompletionStage and exception handling

I've been trying to understand how to properly handle exceptions when using CompletionStage, I've looked at the exceptionally() method but that is not good enough for my needs, I don't want to use it to intercept an exception thrown by an async…
Roberto
  • 15
  • 2
1
vote
1 answer

Task scheduling using acceptEither synchronously on CompletableFuture

I am learning concurrency through the CompletableFuture API. Let's say I have two tasks: one takes 250ms and another takes 2500ms. In the following code: Supplier> supplyIds = () -> { sleep(200); …
1
vote
2 answers

Why the main thread doesn't terminate when there is a completion stage that has not been completed?

This is my simple code: public class Main4 { public static void main(String[] args) { System.out.println("Hello from thread: "+Thread.currentThread().getName()); new Game().run(); System.out.println("I am dying ... "); …
1
2 3