Reputation: 11
I need to develop a client Rest API in Java, that uses a library with asynchronous http. More concretely, I can make Rest CRUD operations, that return a Future of the http Response. My question is, how should my wrapper API deal with these Future objects? Should I just provide the user of the API the Future and it is up to him to deal with it, or should I develop some threading mechanism?
Upvotes: 1
Views: 1948
Reputation: 766
Why it is required ? - I feel it is important to have it as Future for high load systems.
For a web site, if it needs to support high loads, it will be waste of cpu time just to wait on http response. Rather making it a async, makes the http worker more efficient to handle other requests.
Use library which can simplify this for you.
Upvotes: 0
Reputation: 49085
IMHO if I was the consumer of your API I would rather you did not do my multithreading unless:
What I'm saying is I don't thing you will add any value by returning Future's and in fact is annoying if I want to handle the threading myself but all you offer is the async API (returning Future
).
Now making your API client Threadsafe is preferred and does interest me (that is I don't want to have to instantiate a new client everytime I use it).
However if you are using something like async-http-client (NIO) then hell yeah return the Future
.
Upvotes: 2