Questions tagged [completable-future]

In Java 8, a Future that may be explicitly completed (setting its value and status), and may include dependent functions and actions that trigger upon its completion.

Introduced in Java 8, CompletableFuture is a Future that may be explicitly completed (setting its value and status), and may include dependent functions and actions that trigger upon its completion.

When two or more threads attempt to complete, completeExceptionally, or cancel a CompletableFuture, only one of them succeeds. Oracle Documentation

1386 questions
-1
votes
3 answers

stop other service calls if using Completable future to call multiple services if any of service fails

I am using completable future to invoke multiple service calls. CompletableFuture future1 = CompletableFuture.supplyAsync(() -> webServiceCall1()); CompletableFuture future2 = CompletableFuture.supplyAsync(() ->…
ASharma7
  • 726
  • 3
  • 8
  • 27
-1
votes
1 answer

How to implement forEach loop of list using completableFuture of java8

List list1 = new ArrayList(); list1.add("Class1"); list1.add("Class2"); List list2 = new ArrayList(); list2.add("Book1"); list2.add("Book2"); List>…
-1
votes
1 answer

Two queries in parallel closing the Statement and ResultSet respectively causing race condition

I have two queries running in parallel that fetch data from my remote db public CompletableFuture> getAppointments(){ return CompletableFuture.supplyAsync(() -> { return queryAppointments(); …
DIRTY DAVE
  • 2,523
  • 2
  • 20
  • 83
-1
votes
1 answer

Asynchronous execution/operation with CompletableFuture in Java 8+

In Java, is calling get() method while looping on CompletableFuture instances as good as doing synchronous operations although CompletableFuture is used for async calls?
-1
votes
1 answer

CompletableFuture always throws 500 Internal Server Error

I am running web services using spring boot. The below snippet is from controller. I have a custom exception class(which extends RuntimeException). To handle exceptions, I have a controller advice as well. When someMethod() throws a custom…
-1
votes
1 answer

Java CompletableFuture: CompletableFuture coordination

This is my sequential synchronous code: int pageNumber = 0; int pageSize = 100; ResultSetType resultSet; do { resultSet = this.serveiTerritorialClientRepository .getOid("2.16.724.4.400", pageNumber, pageSize); // do…
Jordi
  • 20,868
  • 39
  • 149
  • 333
-1
votes
1 answer

generic version of `allOf` that results a `ComposableFuture` of a generic list

I am trying to understand CompletableFuture API, and I got stuck at the following problem. allOf by itself only returns a CompletableFuture, so it only makes sense to have a slightly better interface with a function called allResultsOf: Such…
lurscher
  • 25,930
  • 29
  • 122
  • 185
-1
votes
1 answer

Await CompletableFutures inside a CompletableFuture?

I am trying to execute an async operation which awaits multiple other async operations. How exactly do I do this with CompletableFutures? Here's what I want to achieve without calling join, I actually want that those triggered operations run async…
genaray
  • 1,080
  • 1
  • 9
  • 30
-1
votes
1 answer

java 8 completablefuture in for loop , force async to sync or like a chain

currently i have a requirement to make async task to sync in completablefuture. Eg. Task A and Task B are completablefuture. Task B runs when Task A is completed. This works fine for single time. Suppose if I make it to run in foor loop, obviously…
-1
votes
1 answer

CompletableFuture Extract from CompletionException

This test fails because I get CompletionException exception but the method throws IllegalArgumentException. So the actual exception wrapped into CompletionException. How can I extract the exception that is wrapped into CompletionException? I tried…
James
  • 441
  • 2
  • 6
  • 9
-1
votes
1 answer

List CompletableFuture

Can you tell me how I can wait for the CompletableFuture list in the parent CompletableFuture, collect their result and return it? CompletableFuture future = CompletableFuture.supplyAsync(() -> { …
LeshaRB
  • 1,345
  • 2
  • 23
  • 44
-1
votes
1 answer

Java - sync call inside async thenCompose

Consider below code as I am not able to find better words to ask the question: CompletionStage callingAsyncFunction(int developerId) { return getManagerIdByDeveloperId(developerId) .thenCompose(id -> …
-1
votes
2 answers

Java CompletableFuture is more concise and faster then Scala Future

I am Java developer and learning Scala at the moment. It is generally admitted, that Java is more verbose then Scala. I just need to call 2 or more methods concurrently and then combine the result. Official Scala documentation at…
Fedor
  • 559
  • 1
  • 7
  • 19
-1
votes
1 answer

How to parallel execute multiple database calls using spring?

I am trying to improve the performance of the spring applications which invokes about 8-10 queries and combined it will take about 15 to 120 seconds depending on the amount of data it queries for, i'm proposing a CompletableFuture / Future way of…
Zeus
  • 6,386
  • 6
  • 54
  • 89
-1
votes
2 answers

how to create new instances of a class for each asynchronus call (made using CompletableFuture)

Here is my code: class A{ @Autowired B objB; public method1(){ List ids = new ArrayList(); ids.add("1"); ids.add("2"); ids.add("3"); List> listOfFuture…
suj sekar
  • 1
  • 3
1 2 3
92
93