Announcement Announcement Module
No announcement yet.
To singleton or not ? Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • To singleton or not ?

    My application has DAOs, Services, Facades and WebWork actions.
    WebWork actions shouldn't be singletons, but what about the other
    domain objects ?

  • #2
    The controllers, services, daos, etc... are stateless (typically). I usually find it's the typical scope for the beans I create.
    The scope of this bean: typically "singleton" (one shared instance,
    which will be returned by all calls to getBean() with the id),
    or "prototype" (independent instance resulting from each call to
    getBean(). Default is "singleton".

    Singletons are most commonly used, and are ideal for multi-threaded
    service objects. Further scopes, such as "request" or "session",
    might be supported by extended bean factories (for example, in a
    web environment).

    Note: This attribute will not be inherited by child bean definitions.
    Hence, it needs to be specified per concrete bean definition.

    Inner bean definitions inherit the singleton status of their containing
    bean definition, unless explicitly specified: The inner bean will be a
    singleton if the containing bean is a singleton, and a prototype if
    the containing bean has any other scope.
    Last edited by karldmoore; Aug 30th, 2007, 06:53 AM.


    • #3
      DAOs and services are ok to be singletons, but what about facades ?
      In my case, each WebWork action use the facade.
      Would you explain more please ?
      Is it ok for the facades to be singletons ?


      • #4
        Anything that's stateless can be a singleton. Anything that has state can be a singleton, but would need to consider threading issues. Otherwise make it one of the other scopes to potentially avoid threading issues.
        Last edited by karldmoore; Aug 30th, 2007, 06:52 AM.