請教各位一個問題,在使用多線程處理集合時,需要設定一個nThreads,請問如下方式是否會與全局(xml文件)設定的線程池沖突?
int dealSize = 200000; // 每次處理的數(shù)量
int index = 0; // 每組的起點下標
int nThreads = 5; // 線程數(shù)量
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
提交
取消