Creator mode - singleton

Watch video: https://www.bilibili.com/video/av43896218/?p=286

Implementation :( private constructor provides a method for providing external access to the examples)

1, starving type: thread-safe, call the high efficiency, the delay can not be loaded

2, lazy type: thread-safe, call the efficiency is not high, the delay can be loaded (to use when it is loaded)

3, double lock detection type: "Due to the underlying JVM internal model, occasional problems, not recommended."

4, static inner classes type: thread-safe, high-efficiency calls, and can achieve load delay

(The above four methods can be destroyed by a single reflection mode embodiment and deserialization)

5, enumerate: thread-safe, high-efficiency calls, the delay can not be loaded, can prevent the reflection of natural and deserialization

Guess you like

Origin www.cnblogs.com/DDiamondd/p/10966745.html