請教各位一個(gè)問題,在使用多線程處理集合時(shí),需要設(shè)定一個(gè)nThreads,請問如下方式是否會與全局(xml文件)設(shè)定的線程池沖突?
int dealSize = 200000; // 每次處理的數(shù)量
int index = 0; // 每組的起點(diǎn)下標(biāo)
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)));
}
添加回答
舉報(bào)
0/150
提交
取消