How is it possible for a program to contain exclusively thread-safe classes, but not be thread-safe?
问题 I am reading "java concurrency in practice", and the author says: "A program that consists entirely of thread-safe classes may not be thread-safe". How is this possible? I don't seem to understand, can someone provide an example? 回答1: An example would be individual methods on a class that are thread safe, but they are not atomic if you invoke more than one. E.g. if (!threadSafeCollection.contains(thing)) { threadSafeCollection.add(thing); } This may yield incorrect results if another thread