On how ArrayList implements thread security, and how arraylist implements threads
I. Use the synchronized keyword
2. Use Collections. synchronizedList ();
Assume that the code you created is as follows: List <Map <String, Object> data = new ArrayList <Map <String, Object> ();
To solve this thread security problem, you can use Collections. synchronizedList (), for example:
List <Map <String, Object> data = Collections. synchronizedList (new ArrayList <Map <String, Object> ());
The methods used are almost the same as those of ArrayList. For details, refer to the api documentation;
In addition, ArrayList and javaslist are both an implementation under the interface List, which have the same usage, but the places used are a bit different. ArrayList is suitable for a large number of random accesses, the rule list is suitable for table insertion and deletion. Both are non-thread-safe. The solution is the same as above (to avoid thread security, the above method is used, especially the second method, in fact, it is very performance-consuming ).