Home Java Technology EJB EJB Sample Interview Questions - 9

Login Form




EJB Sample Interview Questions - 9 Print E-mail

1. The EJB container implements the EJBHome and EJBObject classes.For every request from a unique client, does the container create a separate instance of the generated EJBHome and EJBObject classes?
Answer: The EJB container maintains an instance pool.The container uses these instances for the EJB Home reference irrespective of the client request.while refering the EJB Object classes the container creates a separate instance for each client request.The instance pool maintainence is up to the implementation of the container.If the container provides one, it is available otherwise it is not mandatory for the provider to implement it.Having said that, yes most of the container providers implement the pooling functionality to increase the performance of the application server.The way it is implemented is again up to the implementer.

2. Are enterprise beans allowed to use Thread.sleep()?
Answer: Enterprise beans make use of the services provided by the EJB container, such as life-cycle management.To avoid conflicts with these services, enterprise beans are restricted from performing certain operations: Managing or synchronizing threads

3. Is it possible to specify multiple JNDI names when deploying an EJB?
Answer: No.To achieve this you have to deploy your EJB multiple times each specifying a different JNDI name.

4. I have created a remote reference to an EJB in FirstServlet.Can I put the reference in a servlet session and use that in SecondServlet?
Answer: Yes.The EJB client (in this case your servlet) acquires a remote reference to an EJB from the Home Interface; that reference is serializable and can be passed from servlet to servlet.If it is a session bean, then the EJB server will consider your web client's servlet session to correspond to a single EJB session, which is usually (but not always) what you want.

5. How many types of protocol implementations does RMI have?
Answer: RMI has at least three protocol implementations: Java Remote Method Protocol(JRMP), Internet Inter ORB Protocol(IIOP), and Jini Extensible Remote Invocation(JERI).These are alternatives, not part of the same thing, All three are indeed layer 6 protocols for those who are still speaking OSI reference model.

6. Question With regard to Entity Beans, what happens if both my EJB Server and Database crash, what will happen to unsaved changes? Is there any transactional log file used?
Answer: Actually, if your EJB server crashes, you will not even be able to make a connection to the server to perform a bean lookup, as the server will no longer be listening on the port for incoming JNDI lookup requests.You will lose any data that wasn't committed prior to the crash.This is where you should start looking into clustering your EJB server.Any unsaved and uncommited changes are lost the moment your EJB Server crashes.If your database also crashes, then all the saved changes are also lost unless you have some backup or some recovery mechanism to retrieve the data.So consider database replication and EJB Clustering for such scenarios, though the occurence of such a thing is very very rare.Thx, Uma All databse have the concept of log files(for exampe oracle have redo log files concept).So if data bases crashes then on starting up they fill look up the log files to perform all pending jobs.But is EJB crashes, It depend upon the container how frequenlty it passivates or how frequesntly it refreshes the data with Database.

7. Can you control when passivation occurs?
Answer: The developer, according to the specification, cannot directly control when passivation occurs.Although for Stateful Session Beans, the container cannot passivate an instance that is inside a transaction.So using transactions can be a a strategy to control passivation.The ejbPassivate() method is called during passivation, so the developer has control over what to do during this exercise and can implement the require optimized logic.Some EJB containers, such as BEA WebLogic, provide the ability to tune the container to minimize passivation calls.Taken from the WebLogic 6.0 DTD - "The passivation-strategy can be either "default" or "transaction".With the default setting the container will attempt to keep a working set of beans in the cache.With the "transaction" setting, the container will passivate the bean after every transaction (or method call for a non-transactional invocation)."

8. Does EJB 1.1 support mandate the support for RMI-IIOP ? What is the meaning of "the client API must support the Java RMI-IIOP programming model for portability, but the underlying protocol can be anything"?
Answer: EJB1.1 does mandate the support of RMI-IIOP.There are 2 types of implementations that an EJB Server might provide: CORBA-based EJB Servers and Proprietry EJB Servers.Both support the RMI-IIOP API but how that API is implemented is a different story.(NB: By API we mean the interface provided to the client by the stub or proxy).A CORBA-based EJB Server actually implements its EJB Objects as CORBA Objects (it therefore encorporates an ORB and this means that EJB's can be contacted by CORBA clients (as well as RMI-IIOP clients) A proprietry EJB still implements the RMI-IIOP API (in the client's stub) but the underlying protocol can be anything.Therefore your EJB's CANNOT be contacted by CORBA clients.The difference is that in both cases, your clients see the same API (hence, your client portability) BUT how the stubs communicate with the server is different.

9. Can you control when passivation occurs?

Answer: The developer, according to the specification, cannot directly control when passivation occurs. Although for Stateful Session Beans, the container cannot passivate an instance that is inside a transaction. So using transactions can be a a strategy to control passivation. The ejbPassivate() method is called during passivation, so the developer has control over what to do during this exercise and can implement the require optimized logic. Some EJB containers, such as BEA WebLogic, provide the ability to tune the container to minimize passivation calls. Taken from the WebLogic 6.0 DTD -The passivation-strategy can be either default or transaction. With the default setting the container will attempt to keep a working set of beans in the cache. With the transaction setting, the container will passivate the bean after every transaction (or method call for a non-transactional invocation).

10. What is the advantage of using Entity bean for database operations, over directly using JDBC API to do database operations? When would I use one over the other?

Answer: Entity Beans actually represents the data in a database. It is not that Entity Beans replaces JDBC API. There are two types of Entity Beans Container Managed and Bean Mananged. In Container Managed Entity Bean - Whenever the instance of the bean is created the container automatically retrieves the data from the DB/Persistance storage and assigns to the object variables in bean for user to manipulate or use them. For this the developer needs to map the fields in the database to the variables in deployment descriptor files (which varies for each vendor). In the Bean Managed Entity Bean - The developer has to specifically make connection, retrive values, assign them to the objects in the ejbLoad() which will be called by the container when it instatiates a bean object. Similarly in the ejbStore() the container saves the object values back the the persistance storage. ejbLoad and ejbStore are callback methods and can be only invoked by the container. Apart from this, when you use Entity beans you dont need to worry about database transaction handling, database connection pooling etc. which are taken care by the ejb container.