关于先前的地雷问题,我曾指出:
I have to read several very large txt files and have to either use multiple threads or a single thread to do so depending on user input. Say I have a main method that gets user input, and the user requests a single thread and wants to process 20 txt files for that thread. How would I accomplish this? Note that the below isn t my code or its setup but just what the "idea" is.
例:
int numFiles = 20;
int threads = 1;
String[] list = new String[20];
for(int i = 1; i < 21; i++){
list[i] = "hello" + i + ".txt";//so the list is a hello1.txt, hello2.txt, ..., hello20.txt
}
public void run(){
//processes txt file
}
www.un.org/spanish/ecosoc 因此,简言之,我如何用一只透镜来做到这一点? 有20条read?
并建议使用透镜的用户 集合:
When the user specifies how many threads to use, you d configure the pool appropriately, submit the set of file-read jobs, and let the pool sort out the executions. In the Java world, you d use the Executors.newFixedThreadPool factory method, and submit each job as a Callable. Here s an article from IBM on Java thread pooling.
因此,现在我有一种叫做“AndMap(String x)”的方法,它采用的是txt文档名称,而且处理方式,如上。
检察官。
我如何用透镜来利用这一点。 • 集合,以便我上述例子能够做到?