Mechanism: CopyOnWriteArrayList: A container designed for multi-thread concurrency. It adopts the "copy upon writing" policy. Collections. synchronizedMap: synchronizes containers with an exclusive policy. Result: under the two threads, the access time of Collections. synchronizedMap is about five times that of CopyOnWriteArrayList, but the access time of 64 threads is more than 200 times. Therefore, CopyOnWriteArrayList is the first choice if the container is fully read-only. However, CopyOnWriteArrayList adopts the "copy upon writing" policy. writing to the container will result in the replication of basic arrays in the container, with high performance overhead. Therefore, CopyOnWriteArrayList has poor performance in case of write operations, and overflow may occur if the container capacity is large. In the code, if CopyOnWriteArrayList cl is initialized according to the ArrayList al method, it will cause overflow. The Code is as follows: package test; import java. util. arrayList; import java. util. collections; import java. util. date; import java. util. list; import java. util. random; import java. util. concurrent. copyOnWriteArrayList;/*** @ author Alfred Xu <alfred.xu@heweisoft.com> **/public class ListPerformance {private final int threadNumber; public ListPerformance (int n) {threadNumber = n ;} private static class TestThread implements Runnable {private static long totolTime; private final int No; private final int loop = 100000; private final Thread t; private final List <Integer> list; testThread (int No, List <Integer> list) {this. no = No; this. list = list; t = new Thread (this);} public void start () {t. start () ;}public synchronized void addTime (long time) {toltime + = time ;}@ Override public void run () {long time = randomAccess (); addTime (time) ;}@ Override public String toString () {return "Thread" + No + ":";} public long randomAccess () {Date date1 = new Date (); random random = new Random (); for (int I = 0; I <loop; I ++) {int n = random. nextInt (loop); list. get (n);} Date date2 = new Date (); long time = date2.getTime ()-date1.getTime (); // System. out. println (this + list. getClass (). getSimpleName () // + "time:" + time); return time ;}} public void initList (List <Integer> list, int size) {for (int I = 0; I <size; I ++) {list. add (new Integer (I) ;}} public void test (List <Integer> list) {System. out. println ("Test List Performance"); TestThread [] ts = new TestThread [threadNumber]; for (int I = 0; I <ts. length; I ++) {ts [I] = new TestThread (I, list) ;}for (int I = 0; I <ts. length; I ++) {ts [I]. start () ;}} public static void main (String [] args) {ListPerformance lp = new ListPerformance (64); List <Integer> al = Collections. synchronizedList (new ArrayList <Integer> (); lp. initList (al, 100000); lp. test (al); System. out. println (al. size (); // set the breakpoint here to wait for the Creation thread completely; otherwise, the effect will not be visible to System. out. println (TestThread. totolTime); TestThread. totolTime = 0; CopyOnWriteArrayList <Integer> cl = new CopyOnWriteArrayList <Integer> (al); lp. test (cl); System. out. println (cl. size (); // set the breakpoint here to wait for the Creation thread completely; otherwise, the effect will not be visible to System. out. println (TestThread. totolTime );}}