The singleton pattern commonly used in java design pattern

Singleton pattern is that a class can only create one object
Several implementation methods: lazy mode, hungry mode

Lazy Mode: Thread Unsafe, High Efficiency
Hungry mode: thread safety, low efficiency

To achieve thread safety and high efficiency, you can use double-check lock mode or static inner class mode


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325871283&siteId=291194637