• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Handling multiple requests using CompletableFuture

 
Ranch Hand
Posts: 595
6
jQuery Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 28371
99
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 595
6
jQuery Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
I didn't do it. You can't prove it. Nobody saw me. The sheep are lying! This tiny ad is my witness!
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic