Stateless Session bean calling private methods


EJB design: Stateless Session bean calling private methods

  1. Stateless Session bean calling private methods (7 messages)

      I have created a stateless session bean which calls private method defined in the bean.

      example :
      Remote Method A implementation calls private method B in the same bean class.Now I was wondering about the synchronization issues if two clients call the remote method at the same time ; will this in any way affect the private methods .I know there wont be any problems with the remote method implementation as the app server handles it ; but what about the private method calls.
     Any ideas ?
  2. Hi
     I could have made it a statefull bean; but then i will lose on performance.
     Any suggestions.
  3. EJB guarantees(and I think most of the app server too with some degree of discretion) every client accessing a bean get a separate instance of the bean, regardless of the type of bean. So different clients can call the private method concurrently. There is not any way you can synchronized your method, first of all it is not allowed according to spec, second the semantics of synchronization on an instance method is useless if every thread gets a separate instance of a bean.

  4. Hi Rashid
    i know about synchronization issues as far as remote methods are concerned ; but i am wondering about the private methods that these remote methods call.
     I hope I am sufficiently clear now.
  5. Im not sure I totally understand the question. If there is no thread safety issue with the public methods being called on the beans, and those public methods in turn call their own private methods, why would a thread safety issue then arrise?

    Dave Wolf
    Internet Applications Division
  6. you can set those methods to use transaction so it will garantee isolation of them.

    it won't see each others.
  7. There are a lot discuss in this discussion room. Please seach the answer, then paste your question.

    EJB spec 1.1, section 6.11.6 said you need not worry two clients call the same stateful session bean or session bean in general. The second client will receive RemoteException.

    See the spec. below

    6.11.6 Non-reentrant instances
    The container must ensure that only one thread can be executing an instance at any time. If a client
    request arrives for an instance while the instance is executing another request, the container must throw
    the java.rmi.RemoteException to the second request.
    Note that a session object is intended to support only a single client. Therefore, it would be an
    application error if two clients attempted to invoke the same session object.
    One implication of this rule is that an application cannot make loopback calls to a session bean instance.

  8. ejbs help[ Go to top ]

    Hi, I pretty have the same problem. But not only this... 1) I have the public methods of the bean that have the required transaction attribute. These methods call private methods of the bean (internal methods of the bean) which have no transaction attribute. Are these invocations part of the transaction or not? 2) I want to make a bean of mine invoke a simple java class, basically to init a thread. How can a bean invoke a simple java class and is it allowed to spawn a thread? Guys i am quite new to EJBs (but quite old in Java) so any help would be valuable.