Singleton design pattern depth study

1. There are five singleton pattern written:

1.1 is divided into: general writing, thread lock method (lazy formula), an internal locking thread method, initialize static class attribute (starving formula), the internal class initialization.

1.2 lazy type: create when in use; starving type: created when the class initialization.

1.3 The third is called double-checked locking.

1.4 locking two kinds: synchronized added to the method, which method is called in the synchronized addition sync block: synchronized (Object static object class .class) two kinds of writing.  

1.5 Enumeration singleton: not seen dim.

1.6 serialization issues a single embodiment.

final question 1.7 singleton (see later, little depth): final value must be initialized before you initialize the class.

1.57 Reference:

https://www.cnblogs.com/qq895139140/p/7774152.html

https://www.cnblogs.com/kexianting/p/8977990.html

https://blog.csdn.net/qq_37347341/article/details/77740215

https://q.cnblogs.com/q/DetailPage/95556/

 

Guess you like

Origin www.cnblogs.com/6xiaoxian9/p/10966964.html