8 Replies Latest reply on Sep 6, 2005 2:26 PM by treespace

    Home Interface and Context Thread Safety

      Are EJB home interfaces thread-safe such that we could create it once and use it simultaneously from any number of threads? Google doesn't seem to know the answer to this. There is a mountain of ambiguous and contradictory information on the topic.

      Regarding the Context for looking up the home inteface. Is that thread safe? Google is ambiguous here also. No two references appear to have the same facts.

        • 1. Re: Home Interface and Context Thread Safety
          starksm64

          The thread safety semantics of the home interface proxies is not defined in the spec, so its an implementation detail.

          The Context javadoc is very clear that it is not thread safe:


          A Context instance is not guaranteed to be synchronized against concurrent access by multiple threads. Threads that need to access a single Context instance concurrently should synchronize amongst themselves and provide the necessary locking.



          • 2. Re: Home Interface and Context Thread Safety

            That is frustrating because more than one article exists showing cached JNDI contexts and home objects. Based on your information we need to create the context and perform the home lookup every time we need to make EJB calls.

            Can you confirm that? Are there more efficient yet still portable and reliable alternatives?

            TIA

            • 3. Re: Home Interface and Context Thread Safety
              darranl

              What is your application that is accessing the JNDI contexts and the home interfaces?

              • 4. Re: Home Interface and Context Thread Safety

                I wanted to know whether contexts and home interfaces were reentrant independent of any specific application. Scott indicated neither is (being undefined is just as good as not being reentrant if portability is an issue).

                I am interested in what alternatives exist outside of a lookup/create call each time you need to access a given EJB independent of any specific application.

                • 5. Re: Home Interface and Context Thread Safety
                  darranl

                  The architecture of the application affects what the problem is that needs to be solved and the suitability of different solutions.

                  • 6. Re: Home Interface and Context Thread Safety

                    I have a question regarding the reentrancy of the create call on EJB home objects and whether a context lookup is reentrant if its use is restricted to a lookup. It is safe to assume a multi-threaded J2EE application although that might be redundant.


                    • 7. Re: Home Interface and Context Thread Safety
                      starksm64

                      I would expect most Context.lookup implementations to be thread-safe and hence the prevelant caching examples. The reentrancy of an ejb home create does not make sense to me. A create is a stateless call that has nothing to reenter.

                      • 8. Re: Home Interface and Context Thread Safety

                        I think therefore I can safely cache the context used for lookups. The other issue is overlapping create calls from multiple threads on an EJB home. That it's stateless is promising but you never know if it's scribbling on class values that preclude overlapping calls. Unless it's stipulated it seems risky to re-use home objects.