Announcement Announcement Module
No announcement yet.
Object Pooling/Caching for IoC? Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Object Pooling/Caching for IoC?


    One of the objects that will be wired together for our application will be caching some non-volatile database data. Since this rarely changes instead of having Spring create new objects and do the database reads over and over for every request, it would be great if it would cache the objects and preferrably manage a pool of these objects. Then when a request comes in, an existing object could be reused during the wiring process and returned instead of instantiating a new object.

    Does Spring have this capability as part of the IoC functionality? If yes, how is this configured? It would be great if there could be a minimum number of objects in the pool as well as a maximum number.

    Thank you for your help.



  • #2
    Additional Info

    The objects to be managed are not connected to a database. These objects use java wrappers which have JNI calls to external functionality. The instantiation of the external functionality is quite expensive. I am hoping that a cache of these objects with the JNI reference up and running can be kept around so that when a request comes in the existing objects can be used. This will save substantial time. The external resource can process multiple independent calls without a problem. It really seems to be an issue of how to get both IoC with Spring and the object pooling during the wiring process.

    I hope this additional info helps.



    • #3
      Spring creates by default singleton object - that is they are created only once and the same instance reused. It also supports prototype beans - that is beans which are created each time they are retrieved.
      Spring 2.0 adds scoping which allows the user to plug in custom lifespan of the beans - for example out of the box http session is supported which means that a bean is a singleton inside the same http session but a new instance will be created in a different http session.