6 Replies Latest reply on Nov 26, 2002 7:09 AM by sanne

    class threadsafe

    bpowell

      I know bean classes are threadsafe, but if an slsb instantiates a user class, does the container ensure the class is threadsafe? Is that a standard J2EE container feature?

        • 1. Re: class threadsafe

          Entity classes are thread safe in the sense that bean 'John' can only be used by only client/transaction.
          Bean 'Carol'/'Peter' can be used by others though.

          A statefull sessionbean is threadsafe in the sense that every client has his own instance, otherwise the notion of state would be worthless.

          A stateless sessionbean is threadsafe in the sense that clients share a couple of anonymous bean instances.

          But if you would instantiate a user class in a function, and call a function that for example manipulates a static member, then things could go wrong.

          So I think that the answer is no, because beans in general have instances that could be shared.

          But I'm no expert,

          HTH,

          Sanne

          • 2. Re: class threadsafe
            bpowell

            Thanks for your reply,
            But while the instance of the stateless bean is being used by the client with that particular bean remote method call, the bean has state to itself, correct?
            Then isn't an instance of the user class just like that state, or will a classloader share the user class instance with some other thread from some other client?

            • 3. Re: class threadsafe
              bpowell

              Thanks for your reply,
              But while the instance of the stateless bean is being used by the client with that particular bean remote method call, the bean has state to itself, correct?
              Then isn't an instance of the user class just like that state, or will a classloader share the user class instance with some other thread from some other client?

              • 4. Re: class threadsafe

                Every client has indeed one instance of a slsb.
                So when a slsb is bound to a client, after it is grabbed form a pool, it is thread save. This goes for all beans. But I hesitated myself in the case of slsb. See Enterprise Javabeans p 62/63. One could envision something static or shared going on.

                Closely coupled is the notion of re-entrancy. Say bean A calls bean B, and B calls A again. This is the only situation where you get a sort of thread problem in beans.
                Default this behaviour is not allowed, and it only applies to entity beans.

                • 5. Re: class threadsafe
                  bpowell

                  Which book is that?
                  From what I have read I have never understood that a slsb can share a method with another thread, or I misunderstand you.

                  • 6. Re: class threadsafe

                    Some problems with the forum, I posted a reply yesterday...

                    Look in O'Reilly Enterprise Javabeans.

                    To be clear: an slsb cannot be shared between clienst/threads. Each client has an anonymous bean instance from a pool. The only exception is for entity beans, with possible re-entrancy (Bean A calls bean B, which calls A again: default not possible).

                    My earlier explanation was to exhibit that you should take care that if you use any other (non-EJB) classes then you better make sure they are thread save.

                    Sanne