4 Replies Latest reply on Mar 14, 2008 11:00 AM by domyalex

    Sharing object with READ_COMMITED?

    domyalex

      Hi to all,
      I'm working on my first project using EJB 3.0 and I'm facing some difficulties.
      Long story short, I basically want to share an object across several (stateless and mdb) bean instances; the object is costly (as in minutes might be required) to build and for this reason I would like to just build it once and keep a single instance in memory. The object is kind of like a tree, where read and updates can be performed. I could end up having several of this costly objects laying around (with different internal data).

      What I would like is some sort of mechanism similar to READ_COMMITED for databases (reads at any time as long as there are no writes going on) to manage the concurrency access to the object.
      I understand EJB's specs state that developers should not manage the synchronization of objects, especially resources.
      I'm using JBoss 4.2.2, so I'm taking a look at JBoss Cache 1.4.x, but I can't quite figure out the right approach to the problem.

      Could somebody please show me a high overview of how JBoss Cache could be used in this context?

      Best regards

        • 1. Re: Sharing object with READ_COMMITED?
          manik

          When you say EJB3, are these objects EJB3/JPA entities?

          • 2. Re: Sharing object with READ_COMMITED?
            domyalex

            Hi Manik,
            I'm still in the design phase, so I don't know exactly what this objects I want to share will end up being. I know their general structure and the information they will hold.
            From some search around it seems like making them entities would allow some good results, but I'm concerned about the performance issues.

            Anyway, as I'm still designing, I'm very open to any inputs you might have.

            Is making them entities preferable over, say, having them serializable and managed by JBoss Cache or similar frameworks? What about using the JNDI to expose them? (but then there are all the synchronization issues that arise...)

            Regards

            • 3. Re: Sharing object with READ_COMMITED?
              manik

              There are many tradeoffs that you need to consider, which are specific to your app's requirements.

              If the objects are EJB3 entities, they will already be cached in the 2nd-level cache. JBoss's EJB3 JPA implementation uses Hibernate, which in turn uses JBoss Cache.


              • 4. Re: Sharing object with READ_COMMITED?
                domyalex

                Thanks for the reply manik.

                What if I wanted to have the shared objects as POJOs? Can I use JBoss Cache or other frameworks to share them and coordinate their access?

                Regards