In my servlet I am hitting several URL\'s to check their status and returning the response to user.
Hitting multipe requests takes lot of time: need threads and timo
You need to submit everything upfront, then wait separately. As below, exception handling removed for clarity:
ExecutorService executor = Executors.newFixedThreadPool(10);
List<Future<statusModel>> futures = new ArrayList<>();
for (Map.Entry<String, String> url : urls.entrySet())
{
futures.add(executor.submit(new CallableRequestStatus(url.getValue())));
}
for (Future<statusModel> f : futures) {
results.add((statusModel) f.get(5, TimeUnit.SECONDS));
}