I am calling the multiple rest API and for this i am using the ExecutorService
for parallel processing. Consumer hit my app more than 10 times every seconds and i observed ExecutorService
very slow to response. I have deployed my application on kubernetes
using tomcat web server.
below is my code , not sure what is causing this to slow.
ExecutorService WORKER_THREAD_POOL = Executors.newFixedThreadPool(100);
Collection tasks = new ArrayList();
for( String str: datalist){
tasks.add(new MyThreadPool(str)); // MyThreadPool internally calls the REST API using Google HttpRequest.
}
List<Future<BasePolicy>> futures = null;
try {
long startProcessingTime = System.currentTimeMillis();
futures = WORKER_THREAD_POOL.invokeAll(tasks);
WORKER_THREAD_POOL.shutdown();
if (!WORKER_THREAD_POOL.awaitTermination(60000, TimeUnit.SECONDS)) {
WORKER_THREAD_POOL.shutdownNow();
}
long totalProcessingTime = System.currentTimeMillis() - startProcessingTime;
log.info("total time to complete the thread pool- " + totalProcessingTime);
} catch (InterruptedException e) {
log.error("error occured during ASYNC process ");
e.printStackTrace();
}
log.info("Finished Waiting All threads completed ");
for (Future<Data> mFuture : futures) {
// my logic
}