How does Singleton behave when two threads call the “getInstance()” at the same time?
问题 How does Singleton behave when two threads call the "getInstance()" at the same time? What are the best practices to protect it? 回答1: Firstly, two threads can't call the method at the "same time" - one will be deemed to call it first... called a "race condition". Next, any properly implemented singleton will handle a race condition cleanly. IMHO, this is the cleanest way to implement a thread-safe singleton without synchronization : public class MySingleton { private static class Holder {