单例模式是用得比较多的一种设计模式,也是开发人员最熟悉的一种模式,其表示一个类只有一个实例对象,在《Head First 设计模式》中,其定义如下
单例模式确保一个类只有一个实例,并提供一个全局访问点。 ——《Head First 设计模式》
Thread[pool-1-thread-1,5,main] Construct Singleton class! Thread[pool-1-thread-2,5,main] do something! Thread[pool-1-thread-4,5,main] do something! Thread[pool-1-thread-5,5,main] do something! Thread[pool-1-thread-3,5,main] do something! Thread[pool-1-thread-1,5,main] do something!
Thread[pool-1-thread-4,5,main] Construct Singleton class! Thread[pool-1-thread-1,5,main] do something! Thread[pool-1-thread-2,5,main] do something! Thread[pool-1-thread-4,5,main] do something! Thread[pool-1-thread-5,5,main] do something! Thread[pool-1-thread-3,5,main] do something!
Thread[pool-1-thread-1,5,main] Construct Singleton class! Thread[pool-1-thread-4,5,main] do something! Thread[pool-1-thread-3,5,main] do something! Thread[pool-1-thread-5,5,main] do something! Thread[pool-1-thread-2,5,main] do something! Thread[pool-1-thread-1,5,main] do something!
Thread[pool-1-thread-2,5,main] Construct Singleton class! Thread[pool-1-thread-2,5,main] do something! Thread[pool-1-thread-4,5,main] do something! Thread[pool-1-thread-3,5,main] do something! Thread[pool-1-thread-5,5,main] do something! Thread[pool-1-thread-1,5,main] do something!
Thread[pool-1-thread-3,5,main] do something! Thread[pool-1-thread-5,5,main] do something! Thread[pool-1-thread-2,5,main] do something! Thread[pool-1-thread-1,5,main] do something! Thread[pool-1-thread-4,5,main] do something!