Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. .NET (Core and Framework)
  4. singleton v/s pooling

singleton v/s pooling

Scheduled Pinned Locked Moved .NET (Core and Framework)
designregexarchitecturequestion
11 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    nicetohaveyou
    wrote on last edited by
    #1

    What are the differences between singleton and pooling? If singleton design pattern is used to have just one connection. Also, we know that the connection pooling helps to organise the connections. How are hese two things similar and different? Many Thanks....

    C L 2 Replies Last reply
    0
    • N nicetohaveyou

      What are the differences between singleton and pooling? If singleton design pattern is used to have just one connection. Also, we know that the connection pooling helps to organise the connections. How are hese two things similar and different? Many Thanks....

      C Offline
      C Offline
      Curtis Schlak
      wrote on last edited by
      #2

      A Singleton implementation should guarantee that there is ONE AND ONLY ONE instance of a particular object in a system. A pool is a management object that contains resources. It is generally used to maintain high-cost connections to resources and limit the number of the resources generated by the system.

      "we must lose precision to make significant statements about complex systems." -deKorvin on uncertainty

      N 1 Reply Last reply
      0
      • N nicetohaveyou

        What are the differences between singleton and pooling? If singleton design pattern is used to have just one connection. Also, we know that the connection pooling helps to organise the connections. How are hese two things similar and different? Many Thanks....

        L Offline
        L Offline
        led mike
        wrote on last edited by
        #3

        nicetohaveyou wrote:

        What are the differences between singleton and pooling?

        nicetohaveyou wrote:

        How are hese two things similar and different?

        Well, if you have a Singleton Pool they are one thing and so not different nor similar. ;)

        C 1 Reply Last reply
        0
        • L led mike

          nicetohaveyou wrote:

          What are the differences between singleton and pooling?

          nicetohaveyou wrote:

          How are hese two things similar and different?

          Well, if you have a Singleton Pool they are one thing and so not different nor similar. ;)

          C Offline
          C Offline
          Curtis Schlak
          wrote on last edited by
          #4

          Is there a lifeguard on duty there? 'Cause I'm not that strong of a swimmer....

          "we must lose precision to make significant statements about complex systems." -deKorvin on uncertainty

          L 1 Reply Last reply
          0
          • C Curtis Schlak

            Is there a lifeguard on duty there? 'Cause I'm not that strong of a swimmer....

            "we must lose precision to make significant statements about complex systems." -deKorvin on uncertainty

            L Offline
            L Offline
            Luc Pattyn
            wrote on last edited by
            #5

            You might ask that question in the get-together forum. My best guess is the guard is in one of the lounges though. :)

            Luc Pattyn [Forum Guidelines] [My Articles]


            - before you ask a question here, search CodeProject, then Google - the quality and detail of your question reflects on the effectiveness of the help you are likely to get - use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets


            P 1 Reply Last reply
            0
            • C Curtis Schlak

              A Singleton implementation should guarantee that there is ONE AND ONLY ONE instance of a particular object in a system. A pool is a management object that contains resources. It is generally used to maintain high-cost connections to resources and limit the number of the resources generated by the system.

              "we must lose precision to make significant statements about complex systems." -deKorvin on uncertainty

              N Offline
              N Offline
              nicetohaveyou
              wrote on last edited by
              #6

              Can we have a practical explanation of that? More elaborate... t.a.

              C 1 Reply Last reply
              0
              • N nicetohaveyou

                Can we have a practical explanation of that? More elaborate... t.a.

                C Offline
                C Offline
                Curtis Schlak
                wrote on last edited by
                #7

                Sure.

                Singleton Example

                Let's say that you're implementing an interpreter for a scripting language that contains some mathematical operators. Now, you design your language so that none of the objects that implement the operators (such as AddOperator, MultOperator) have state, just a collection of methods. To reduce the memory consumption of the interpreter, you can choose to have each of those operators as singletons, one instance of the AddOperator will exist in any AppDomain. This is in contrast to parsing the input and creating an AddOperator into an abstract syntax tree every time the parser encounters the + symbol.

                Pool Example

                Quite often in multi-threaded applications that access data from a persistent store, the connections that the applications use to connect to the persistent store are pooled. For example, it's a common practice to pool a certain number of connections to a database because it's so darn expensive to create the connection. Then, when an application wants to get data from the database, it asks the pool for a connection instead of creating its own.

                I think that your confusion may be coming from the thought that "a resource pool is a singleton." That can be true and quite often is. In general, why would you create multiple pools of resource connections when that kind of defeats the purpose of having that limited number of expensive connections?

                "we must lose precision to make significant statements about complex systems." -deKorvin on uncertainty

                N S 2 Replies Last reply
                0
                • C Curtis Schlak

                  Sure.

                  Singleton Example

                  Let's say that you're implementing an interpreter for a scripting language that contains some mathematical operators. Now, you design your language so that none of the objects that implement the operators (such as AddOperator, MultOperator) have state, just a collection of methods. To reduce the memory consumption of the interpreter, you can choose to have each of those operators as singletons, one instance of the AddOperator will exist in any AppDomain. This is in contrast to parsing the input and creating an AddOperator into an abstract syntax tree every time the parser encounters the + symbol.

                  Pool Example

                  Quite often in multi-threaded applications that access data from a persistent store, the connections that the applications use to connect to the persistent store are pooled. For example, it's a common practice to pool a certain number of connections to a database because it's so darn expensive to create the connection. Then, when an application wants to get data from the database, it asks the pool for a connection instead of creating its own.

                  I think that your confusion may be coming from the thought that "a resource pool is a singleton." That can be true and quite often is. In general, why would you create multiple pools of resource connections when that kind of defeats the purpose of having that limited number of expensive connections?

                  "we must lose precision to make significant statements about complex systems." -deKorvin on uncertainty

                  N Offline
                  N Offline
                  nicetohaveyou
                  wrote on last edited by
                  #8

                  Thanks for explanation. However, could you please select another example. Call me a dumbo, but i am in a loss of differentiating between the two. For example, if i have a web application where there are 7 odd connections strings. Do i hav to use the Singleton or just use Pooling to take care of that? You are already writing good and helping my understanding. Appreciate Much!

                  1 Reply Last reply
                  0
                  • C Curtis Schlak

                    Sure.

                    Singleton Example

                    Let's say that you're implementing an interpreter for a scripting language that contains some mathematical operators. Now, you design your language so that none of the objects that implement the operators (such as AddOperator, MultOperator) have state, just a collection of methods. To reduce the memory consumption of the interpreter, you can choose to have each of those operators as singletons, one instance of the AddOperator will exist in any AppDomain. This is in contrast to parsing the input and creating an AddOperator into an abstract syntax tree every time the parser encounters the + symbol.

                    Pool Example

                    Quite often in multi-threaded applications that access data from a persistent store, the connections that the applications use to connect to the persistent store are pooled. For example, it's a common practice to pool a certain number of connections to a database because it's so darn expensive to create the connection. Then, when an application wants to get data from the database, it asks the pool for a connection instead of creating its own.

                    I think that your confusion may be coming from the thought that "a resource pool is a singleton." That can be true and quite often is. In general, why would you create multiple pools of resource connections when that kind of defeats the purpose of having that limited number of expensive connections?

                    "we must lose precision to make significant statements about complex systems." -deKorvin on uncertainty

                    S Offline
                    S Offline
                    supercat9
                    wrote on last edited by
                    #9

                    In general, why would you create multiple pools of resource connections when that kind of defeats the purpose of having that limited number of expensive connections? Designing an architecture around singleton objects that hold state may lead to problems if requirements change in unexpected ways. Even if it's expected that the singleton will be associated with a hardware resource of which there will never be more than one (e.g. the current display monitor) it's possible that there may in future be a need to support more than one such resource, no matter how unlikely it may seem today. That having been said, the proper type of object is something like a singleton, in that at most one such object should be associated with any particular hardware resource, and the object should persist as long as anyone has use for it. There are other pooling situations, like thread pools, where sharing one pool between different parts of an application may lead to resource starvation. While there may be ways of having a single pool implement a suitable prioritization strategy to ensure that every separately-designated part of an application is allowed to have at least one thread running at a time from a shared pool, having different parts use different pools may be simpler.

                    C 1 Reply Last reply
                    0
                    • S supercat9

                      In general, why would you create multiple pools of resource connections when that kind of defeats the purpose of having that limited number of expensive connections? Designing an architecture around singleton objects that hold state may lead to problems if requirements change in unexpected ways. Even if it's expected that the singleton will be associated with a hardware resource of which there will never be more than one (e.g. the current display monitor) it's possible that there may in future be a need to support more than one such resource, no matter how unlikely it may seem today. That having been said, the proper type of object is something like a singleton, in that at most one such object should be associated with any particular hardware resource, and the object should persist as long as anyone has use for it. There are other pooling situations, like thread pools, where sharing one pool between different parts of an application may lead to resource starvation. While there may be ways of having a single pool implement a suitable prioritization strategy to ensure that every separately-designated part of an application is allowed to have at least one thread running at a time from a shared pool, having different parts use different pools may be simpler.

                      C Offline
                      C Offline
                      Curtis Schlak
                      wrote on last edited by
                      #10

                      Right you are! That's why I started it with "In general." :) Special cases for anything exist.

                      "we must lose precision to make significant statements about complex systems." -deKorvin on uncertainty

                      1 Reply Last reply
                      0
                      • L Luc Pattyn

                        You might ask that question in the get-together forum. My best guess is the guard is in one of the lounges though. :)

                        Luc Pattyn [Forum Guidelines] [My Articles]


                        - before you ask a question here, search CodeProject, then Google - the quality and detail of your question reflects on the effectiveness of the help you are likely to get - use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets


                        P Offline
                        P Offline
                        PIEBALDconsult
                        wrote on last edited by
                        #11

                        Visions of Pamela Anderson running in slow motion... :cool:

                        1 Reply Last reply
                        0
                        Reply
                        • Reply as topic
                        Log in to reply
                        • Oldest to Newest
                        • Newest to Oldest
                        • Most Votes


                        • Login

                        • Don't have an account? Register

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • World
                        • Users
                        • Groups