ringa_lee2017-04-18 10:43:42
ArrayList is not inherently thread-safe. You can try it with the List returned by Collections.synchronizedList()
迷茫2017-04-18 10:43:42
In this example, the two cases of ArrayList and CopyOnWriteArrayList are tested respectively. ArrayList will generate fast-fail events, but CopyOnWriteArrayList will not generate fast-fail events.
When using ArrayList, a fast-fail event will be generated and a ConcurrentModificationException exception will be thrown; the definition is as follows:
private static List<String> list = new ArrayList<String>();
When using CopyOnWriteArrayList, no fast-fail event will be generated; the definition is as follows:
private static List<String> list = new CopyOnWriteArrayList<String>();
迷茫2017-04-18 10:43:42
If it is set to 100000000, an exception will be thrown. . .
Use CopyOnWriteArrayList or ThreadLocal to put ArrayList in multi-threads