我知道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))));
}