In my payment processing service I have two different webservice calls. First call to get customer's details and second call to payment gateway service for payment processing. These calls are not dependant on each other and can be called in any order.
Payment gateway call configured with 30 seconds timeout and customer detail call with 10 seconds. Currently calling them synchronously takes 40 seconds (30 + 10).
I want these calls to be made asynchronously for the performance reason. Calling them asynchronously will save 10 seconds processing as when payment gateway is processing the concurrent call to the customer details could be completed in the mean time.
How to implement this in java elegantly?
For example, you can do this with ExecutorService + Callable.
Make two classes that implements Callable interface, create executor service, add two tasks to service and get features. From futures get result of calls.