How can EJB Container guarantee threads safety?

Discussions

EJB design: How can EJB Container guarantee threads safety?

  1. I.e. a session bean performing an important and complex banking operation, then how can container guarantee the integrality of the key operation when more than one client access the same session bean? I think probably all concurrency control problem can boil down to a problem of entity bean, for session bean means business logic which has no need to worry about concurrency problem unless entity bean appears. Transaction may be a possible solution.
  2. By using Transactions and defining the Isolation level you can achieve the desired safety.
  3. By using Transactions and defining the Isolation level you can achieve the desired safety.


    Thanks for your reply.However,I'm not quite clear about the expense of Transaction.Performance is the key design issue in my project.
  4. I think, there is no way to get win win in transaction and performance.

    Regards,
    Wallace
  5. "Ejb container provides scurity by default.If a client is accessing an instance
    it locks it untill it completes utilization,by passivating or removing.
    By definiing isolation it can provide this.Two of the best isolation levels are TRANSACTION_READ_UNCOMMITED,TRANSACTION_SERIALIZABLE "
  6. As per the spec, no two threads will ever access the same EJB bean instance at the same time (neither session, nor entity).

    This removes the risk of threading-unsafe code in an EJB.

    So, if you write a Session EJB, no two threads will ever be executing code in the same instance of the bean.
  7. You are right.But what frighten me is not the fact that two threads will access the same EJB bean instance.In fact,I mean two client threads access two instances of the same EJB bean.
  8. Use suitable isolation level[ Go to top ]

    When you have multiple instances of the same entity bean, the concurrency is similar to ordinary Java class. Only, ejb provide deployment descriptor. You need to specify the suitable transaction attributes.
  9. What is your problem in that scenario?