关于线程安全,有这么一段描述:
A class is thread-safe if it behaves correctly when accessed from multiple threads, regardless of the scheduling or interleaving of the execution of those threads by the runtime environment, and with no additional synchronization or other coordination on the part of the calling code.
即在多线程的环境下,无论线程如何被调度,线程间有怎样的交错,程序都能表现出正确的行为。
但仔细研究ArrayList
的源码就会发现,它并不满足这一描述。