请教各位一个问题,在使用多线程处理集合时,需要设定一个nThreads,请问如下方式是否会与全局(xml文件)设定的线程池冲突?
int dealSize = 200000; // 每次处理的数量
int index = 0; // 每组的起点下标
int nThreads = 5; // 线程数量
ExecutorService service = Executors.newFixedThreadPool(nThreads);
List<Future<List<String>>> futures = new LinkedList<Future<List<String>>>();
for (int i = 0; i < nThreads; i++)
{
int start = index;
index += dealSize;
if (start >= list.size())
break;
int end = start + dealSize;
end = end > list.size() ? list.size() : end;
futures.add(service.submit(new Task(list, start, end)));
}
添加回答
举报
0/150
提交
取消