Java Singleton Design Pattern : Questions

后端 未结 11 559
渐次进展
渐次进展 2021-01-30 11:39

I had an interview recently and he asked me about Singleton Design Patterns about how are they implemented and I told him that using static variables and static methods we can i

11条回答
  •  梦毁少年i
    2021-01-30 12:28

    a static field can have multiple occurrences in one JVM - by using difference class loaders, the same class can be loaded and initialized multiple times, but each lives in isolation and JVM treat the result loaded classes as completely different classes.

    I don't think a Java programmer should care, unless he's writing some frameworks. "One per VM" is a good enough answer. People often talk that way while strictly speaking they are saying "one per classloader".

    Can we have one singleton per cluster? Well that's a game of concepts. I would not appreciate an interviewer word it that way.

提交回复
热议问题