In the previous question I posted:
I need to read some very large txt files and use either multiple threads or one thread to do this depending on user input. Let's say I have a main method that receives user input, and the user requests one stream and wants to process 20 txt files for that stream. How would I do that? Please note that the following is not my code or its setting, but only what is an “idea”.
Example:
int numFiles = 20;
int threads = 1;
String[] list = new String[20];
for(int i = 1; i < 21; i++){
list[i] = "hello" + i + ".txt";
}
public void run(){
}
So how can I do this with a single thread? With 20 threads?
And the user suggested using threadPools:
, , , .
Java Executors.newFixedThreadPool factory . IBM Java.
, sortAndMap (String x), txt , ,
Executors.newFixedThreadPool(numThreads);
threadPools, ?