Most common examples of misuse of singleton class

后端 未结 11 997
伪装坚强ぢ
伪装坚强ぢ 2020-12-16 00:19

When should you NOT use a singleton class although it might be very tempting to do so? It would be very nice if we had a list of most common instances of \'singletonitis\' t

11条回答
  •  盖世英雄少女心
    2020-12-16 01:01

    When you have multiple applications running in the same JVM.

    A singleton is a singleton across the entire JVM, not just a single application. Even if multiple threads or applications seems to be creating a new singleton object, they're all using the same one if they run in the same JVM.

提交回复
热议问题