Java singleton class vs JSF application scoped managed bean - differences?

前端 未结 1 1839
我寻月下人不归
我寻月下人不归 2020-12-06 17:59

Is there a difference using a singleton class and an application scoped managed bean to hold application data?

I need to lookup certain JNDI ressources such as remot

相关标签:
1条回答
  • 2020-12-06 18:46

    Singletons are not unit testable nor abstractable nor extendable. Singletons are also unnecessarily complex to reliably create and maintain if your sole purpose is to have application scoped data (at least, if you really want a fullworthy singleton for it for some reason -most starters don't even exactly understand what a singleton is supposed to be).

    "Just create one" like an application scoped managed bean is much simpler to develop, test and maintain. JSF as framework will guarantee that only one instance will be created and reused during web application's lifetime.

    See also:

    • Singleton vs Just Create one
    • How to choose the right bean scope?
    0 讨论(0)
提交回复
热议问题