BEA Weblogic Question:
Download Questions PDF

An instance of stateful session EJB when accessed simultaneously from more than one clients on same VM results in RemoteException or EJBException. In case the client is a Servlet thread, which of the following techniques can be used to avoid RemoteException/EJBException?

Answer:

a. Not possible.
b. Store the reference to the EJB instance as an instance variable of Servlet class.
c. Store the reference to the EJB instance as a local variable of Servlet class.
d. Make the Servlet client to be remote instead of internal to WebLogic server.


Choice C is the correct choice. An instance of a stateful session EJB can be accessed from only one client virtual machine at a time. Multiple client threads from the same virtual machine can access the same instance of a stateful session EJB, but they must do so in a serial fashion. If a client-invoked business method is in progress on an instance when another client-invoked call, from the same or different client, arrives at the same instance of a stateful session bean class, the container may throw the java.rmi.RemoteException to the second client , if the client is a remote client, or the javax.ejb.EJBException, if the client is a local client. Thus choice D is incorrect.
To avoid any exception, each Servlet should store a reference to a particular EJB instance in a local variable of the Servlet's service() method. Please note that variables local to methods like service(), doGet(), doPost() are not shared between different requests and are automatically thread safe. Thus choice C is correct. An instance variable unlike local variable is shared. Thus Choice B is incorrect.
An implication of this rule is that an application cannot make loop back calls to a session bean instance.
This restriction does not apply to a stateless session bean because the container routes each request to a different instance of the session bean class.

Download BEA Weblogic Interview Questions And Answers PDF

Previous QuestionNext Question
Why does executing the PreparedStatement class cause a TRUNC fails: ORA-00932: inconsistent datatypes error?How do I start WLS and configure JMS?