[Q] Is EJB remote reference thread-safe?

Discussions

EJB programming & troubleshooting: [Q] Is EJB remote reference thread-safe?

  1. [Q] Is EJB remote reference thread-safe? (5 messages)

    Hi,

    Could anyone tell me whether it is OK for multiple CLIENT threads to access the same EJBRemote object? Is the answer different for Stateless/Stateful/Entity beans?

    Thanks
    Ravi
  2. EJB instances are not thread safe. EJB methods are not allowed to be synchronized or contain synchronized blocks. I believe that is in the EJB specification. You must synchronize the remote EJB reference in your client code.
  3. No it is not save (I remember it from 1.2 spec and I expect it remains)
    You mast have own instance for each thread or you mast synchronize access in yout client.
  4. Even though the EJB remote reference may not be thread safe, the EJB container serializes all calls to a particular instance of the EJB, i.e., there is only one thread accessing a particular EJB at a given time.
  5. The serialization is done for different requests of sifferent clients. If you use same instance of the EJBObject you can have trouble there.
  6. I need some clarification. Let's say in my servlet I have an instance variable for an EJBObject, and then in the init() method I create a remote reference to the EJB and assign it to the instance variable. Since this servlet does not implements the SingleThreadedModel, are you saying when several browser clients call this servlet simultaneously and the servlet in turn call a business method on the EJB through the remote reference, the EJB container does not serialize the calls? Did I misunderstood you?