我知道ArrayList是线程不安全的类,在多线程情况下不能直接进行add(),remove(),但是是不是可以使用set(int index, E element)方法,
List<T> records = InstanceUtil.newArrayList();
for (int i = 0; i < ids.getRecords().size(); i++) {
records.add(null);
}
ExecutorService executorService = Executors.newFixedThreadPool(5);
for (int i = 0; i < ids.getRecords().size(); i++) {
final int index = i;
executorService.execute(() -> records.set(index, queryById(ids.getRecords().get(index))));
}