Java Singleton vs static - is there a real performance benefit?

前端 未结 7 2017
抹茶落季
抹茶落季 2021-02-04 06:46

I am merging a CVS branch and one of the larger changes is the replacement wherever it occurs of a Singleton pattern with abstract classes that have a static initialisation bloc

7条回答
  •  北海茫月
    2021-02-04 06:59

    From a strict runtime performance point of view, the difference is really negligible. The main difference between the two lies down in the fact that the "static" lifecycle is linked to the classloader, whereas for the singleton it's a regular instance lifecycle. Usually it's better to stay away from the ClassLoader business, you avoid some tricky problems, especially when you try to reload the web application.

提交回复
热议问题