Implement a thread-safe ArrayList in Java by locking
问题 I want to write a simple thread-safe arraylist which supports: add(), remove(int i), insert(int i), update(int i), and get(int i) One simple implementation is to add lock to the internal data structure(an object array for example), but it is not good enough because only one thread could access the list at a time. Therefore my initial plan is to add lock to each data slot so that different threads could have access to elements in different indexes at the same time. The data structure will look