Executors.newFixedThreadPool() - how expensive is this operation

Viewed 1443

I have a requirement where i need to process some tasks for current live shows. This is a scheduled tasks and runs every minute.

At any given minute, there can be any number of live shows(though number cannot be that large, approx max 10). There are more than 20 functionalities needs to be done for all the live shows. or say 20 worker classes are there , all are doing there job.

Let say for first functionality, there are 5 shows, then after few minutes shows reduced to 2, then again after few minutes shows increase to 7.

Currently i am doing something like this,

int totalShowsCount = getCurrentShowsCount();
ExecutorService executor = Executors.newFixedThreadPool(showIds.size());

The above statements gets executed every minute.

Problem Statement

1.) How much expensive the above operation be..??. Creating fixedThreadPool at every given minute.

2.) What can i do to optimize my solution, should i use a fixed thread pool, say (10), and maybe 3 or 5 or 6 or any number of threads getting utilized at any given minute.

Can i create a fixed thread pool at worker level, and maintain it and utilize that.

FYI, using Java8, if any better approach is available.

1 Answers
Related