ArrayList is not Thread safe.what happens to thread safety when arraylist is passed as开发者_高级运维 a method parameter.Method Parameters are generally thread safe
You cannot 'add' thread-safety like that.
If a class is not thread-safe you need to access it inside lock
statements or something similar.
I think you're a little muddled up between the stack and the heap. The handle/reference to you ArrayList passed as a method parameter is on the stack and therefore Thread-safe since the stack owned by that Thread is the only one that can access that reference.
However, the actual ArrayList lives in the heap and therefore many threads can access it at the same time and therefore you need to protect with some form of synchronization or, depending on the API, you may be able to get a "Synchronized" version of the ArrayList itself.
精彩评论