Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Handling multiple requests using CompletableFuture

 
Ranch Hand
Posts: 590
6
jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
I have a multi threading problem where there are bunch of requests which will take varied time for processing. I want to  get response of all the requests and consume the responses.

My plan is to use CompletableFuture but not able to come up with how to code it. I created a mock up using ExecutorService and here too I am not sure how to handle the future result.
Would it be better to wait for a response with blocking call such as get() or should I use a while loop and loop around until all results are either done or canceled?

Here is the current mock up :
TimeUtil.java


DummyRequest.java


RequestHandler.java


VariableTimedRequestProcessing.java


Would like to get advice on:
1) handling future result in current case.
2) if I use CompletableFuture, what should be the approach to this problem ?

Thanks
 
Marshal
Posts: 25682
69
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


You could do that. I'm not sure what the difference would be if you used CompletableFuture instead but perhaps you could explain what you thought the difference would be when you planned to use it.
 
s ravi chandran
Ranch Hand
Posts: 590
6
jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Paul Clapham wrote:

You could do that. I'm not sure what the difference would be if you used CompletableFuture instead but perhaps you could explain what you thought the difference would be when you planned to use it.


Thanks for the response. I updated my function with what you provided, hope this is how we should be handling the future results.


Coming back to by intention of using CompletableFuture, well I wanted to create sort of workflow pipeline and handle the result from all requests asynchronously.
But as I need the list of responses to process those further, that part is little murky for now.

Here is an incomplete code which I am trying to work out.
    Bookmark Topic Watch Topic
  • New Topic