Announcement Announcement Module
Collapse
No announcement yet.
what is singleton in Spring? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • what is singleton in Spring?

    Hi ,

    can somebody explained what is the purpose/benefit of singleton in Spring
    in real worl analogy ?

    I know a lot people saying that singleton means per application context.

    If i have a static variable on my jsp page.
    will singleton=false will keep initialise the variable everytime i re visit the page?



    Thanks.

  • #2
    Hi Kid

    (I am assuming that you have read that section of the Spring reference manual that details the various scopes, including the section devoted specifically to the singleton scope.)

    If you want a brand spanking new bean (Spring-managed object) for each and every distinct request in your web application, you need the request scope introduced in Spring 2.0.

    Perhaps if you explained in a little more depth what it is you are trying to do someone will be able to provide a more pertinent answer.

    Cheers
    Rick

    Comment


    • #3
      Typically business objects are singleton, for example, the object that contains operations to database, are singleton objects. All operations that doesn't need state after its execution, like conversion tools, math operations, signing data, encrypt data, ... are singleton too.

      In 90 % of cases a singleton approach is the best.

      Comment


      • #4
        Perhaps this thread will help explain, if the Spring documentation 2.0 does not explain it better:

        http://forum.springframework.org/showthread.php?t=25763

        Ben

        Comment

        Working...
        X