在多线程中,使用ArrayList 进行remove操作时,会报异常。改用CopyOnWriteArrayList,若再进Collections.sort(copyOnWriteArrayList, myComparator)时,会报异常:
java.lang.UnsupportedOperationException
因为CopyOnWriteArrayList不支持set()操作。
解决办法是:
List temp = Arrays.asList(copyOnWriteArrayList.toArray());Collections.sort(temp);copyOnwriteArrayList.clear();copyOnWriteArrayList.addAll(temp);