Reputation: 2931
In my current work, for a use case we are making several remote service calls (SOAP over HTTP) in sequence. These are independent calls and I have to collate the data from each call and finally prepare my response. I want to parallelize these calls.
Upvotes: 0
Views: 87
Reputation: 23565
Spawning threads in Java EE is a no-go we're told. However, the OP doesn't say whether Java EE or Java SE is used.
For Java EE the WorkManager API may be useful.
Other than that yes, ExecutorService
or Spring TaskScheduler (rather unlikely if I got the problem right).
Upvotes: 0
Reputation: 272437
Sounds like you should use an ExecutorService.
Make a class that performs your query and implements Runnable. You can then submit instances of this class to an Executor
and it will look after running this in multiple threads (pooling etc. - all configurable). You get given back a Future object for each submission and you simply call get()
on that to get your result.
The framework means you don't have to worry about instantiating threads, setting up pooling, determining what's run etc.
Here's the tutorial.
Upvotes: 2