Код: Выделить всё
package test;
import java.util.concurrent.Executors;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
public class test {
private static final List list = new ArrayList();
private static final CopyOnWriteArrayList stringList
= new CopyOnWriteArrayList();
public static void main(String[] args) {
for(int k=0;k {
int start = threadIndex * chunkSize;
int end = (threadIndex == threadCount - 1) ? size : (threadIndex + 1) * chunkSize;
for (int j = start; j < end; j++) {
stringList.add(list.get(j).toString());
}
});
}
}
}
Подробнее здесь: https://stackoverflow.com/questions/787 ... ecessary-t