4 Replies Latest reply on Sep 2, 2010 2:36 AM by ajuba

    POJO Cache as singleton?

    brucespringfield

      Are there any known problems of using a POJO Cache as a singleton?

        • 1. Re: POJO Cache as singleton?
          jacobeukes

          Hi Bruce. Will it be possible to tell me if you've found a solution to your question ? I am having a problem which seems related to what you are asking. I want to access a JBossCache instance from several places in the same application, but am unable to do so. I would have thought that JBossCache would have a single instance of the cache and manage it "behind the scenes" .. so that the same cache can be accessed from anywhere in the JVM. This doesn't seem to be the case though. Am I correct in my assumption that this kind of functionality is not supported and that a developer will have to build it in him/herself by using a singleton or some other related solution ?

          Thanks for your time and help

          • 2. Re: POJO Cache as singleton?
            brucespringfield

             

            "jacobeukes" wrote:
            Hi Bruce. Will it be possible to tell me if you've found a solution to your question ?


            In my case, there wasn't a need to use a singleton since when the cache is deployed as a service, every time I accessed the cache, I was accessing the Mbean.

            "jacobeukes" wrote:

            I am having a problem which seems related to what you are asking. I want to access a JBossCache instance from several places in the same application, but am unable to do so.


            You might try to deploy it as an Mbean service.

            "jacobeukes" wrote:

            I would have thought that JBossCache would have a single instance of the cache and manage it "behind the scenes" .. so that the same cache can be accessed from anywhere in the JVM.


            That's my experience with it.

            "jacobeukes" wrote:

            Am I correct in my assumption that this kind of functionality is not supported and that a developer will have to build it in him/herself by using a singleton or some other related solution ?


            No.



            • 3. Re: POJO Cache as singleton?
              genman


              It's best to use JNDI to bind and access your cache instance.

              There are many reasons not to create a single instance for all objects, the main one being each application you may run may want a different POJO cache configuration.

              • 4. Re: POJO Cache as singleton?
                ajuba

                Hi Eric,

                I am using pojo cache as singleton by making a wrapper singleton class and instantiating the pojo cache inside wrapper class.

                 

                 

                Thanks

                Ajuba