I currently need to create multiple threadpools. Each threadpool is a single threaded threadpool. I assign tasks to each threadpool based upon a condition. So I need to maintain track of threadpools.
How can I do that? Can I create an array of threadpools?
ExecutorService executor = Executors.newSingleThreadExecutor();
This is how we create 1 threadpool. Now I want to create 5 threadpools.
ExecutorService[] executor;
for(int i=0;i<5;i++){
executor[i]= Executors.newSingleThreadExecutor();
}
Is this ok? Is this right syntax? If not, can you suggest a way to do it?
In your scenario, I believe it is possible to use just one single thread Executor since according to the documentation:
Therefore with multiple input from multiple companies, the queue of the Executor will look like:
And the Executor will process it sequentially.