How can beginners of ejbs face the frequent eleven questions?

Source: Internet
Author: User

1. What does EJB2.0 have? Where are they used? What is the difference between EJB2.0 and EJB1.1?

A: The specifications include Bean providers, application assemblers, EJB containers, EJB configuration tools, EJB service providers, and system administrators. In this regard, the EJB container is the core of the reason why EJB can run. The EJB container manages important core tasks such as creating, revoking, activating, removing, and connecting to the database. JSP, Servlet, EJB, JNDI, JDBC, JMS .....

  2. What is the difference between EJB and java bean?

A: Java Bean is a reusable component and there is no strict specification for Java Bean. Theoretically, any Java class can be a Bean. However, since Java Beans are created by containers (such as Tomcat), Java Beans should have a constructor without parameters. In addition, generally, Java Bean must implement the Serializable interface to realize Bean persistence. Java Bean is actually equivalent to the COM component in the local process in the Microsoft COM model. It cannot be accessed across processes. Enterprise Java Bean is equivalent to DCOM, which is a distributed component. It is based on Java remote method call (RMI) technology, so EJB can be remotely accessed (cross-process, cross-computer ). However, EJB must be deployed in containers such as Webspere and WebLogic. The EJB client never directly accesses the real EJB component but accesses it through its container. The EJB container is the proxy of the EJB component. The EJB component is created and managed by the container. The customer accesses the real EJB component through the container.

  2. What technologies are EJB implemented based on? And the difference between SessionBean and EntityBean, and the difference between StatefulBean and StatelessBean.

A: EJB includes Session Bean, Entity Bean, and Message Driven Bean. It is implemented based on technologies such as JNDI, RMI, and JAT.

SessionBean is used in J2EE applications to perform some server-side business operations, such as accessing the database and calling other EJB components. EntityBean is used to represent the data used in the application system.

For clients, SessionBean is a non-persistent object that implements some business logic running on the server.

For clients, EntityBean is a persistent object that represents an object view of an object stored in persistent storage or an entity implemented by an existing enterprise application.

Session Bean can be further subdivided into Stateful Session Bean and Stateless Session Bean. Both Session beans can execute the system logic in method, the difference is that the Stateful Session Bean can record the caller's status. Therefore, a user usually has a corresponding Stateful Session Bean entity. Although Stateless Session Bean is also a logical component, it is not responsible for recording the user status, that is, when the user calls Stateless Session Bean, the EJB Container does not find the entity of the specific Stateless Session Bean to execute this method. In other words, when several users execute a Stateless Session Bean's methods, they will execute the same Bean Instance. In terms of memory, compared with Stateful Session Bean and Stateless Session Bean, Stateful Session Bean consumes a large amount of memory on the J2EE Server, however, the advantage of Stateful Session Bean is that it can maintain the user's status.

  3. What is the difference between EJB and java bean?

A: Java Bean is a reusable component and there is no strict specification for Java Bean. Theoretically, any Java class can be a Bean. However, since Java Beans are created by containers (such as Tomcat), Java Beans should have a constructor without parameters. In addition, generally, Java Bean must implement the Serializable interface to realize Bean persistence. Java Bean is actually equivalent to the COM component in the local process in the Microsoft COM model. It cannot be accessed across processes. Enterprise Java Bean is equivalent to DCOM, which is a distributed component. It is based on Java remote method call (RMI) technology, so EJB can be remotely accessed (cross-process, cross-computer ). However, EJB must be deployed in containers such as Webspere and WebLogic. The EJB client never directly accesses the real EJB component but accesses it through its container. The EJB container is the proxy of the EJB component. The EJB component is created and managed by the container. The customer accesses the real EJB component through the container.

EJB includes (SessionBean, EntityBean) to indicate their lifecycles, and how to manage transactions?

SessionBean: the lifecycle of Stateless Session Bean is determined by the container. When the client sends a request to create a Bean instance, the EJB container does not have to create a new Bean instance for the client to call. Instead, it finds an existing instance and provides it to the client. When the client calls a Stateful Session Bean for the first time, the container must immediately create a new Bean instance on the server and associate it with the client, when this client calls the Stateful Session Bean method later, the container will dispatch the call to the Bean instance associated with this client.

EntityBean: Entity Beans can survive for a relatively long time, And the status is continuous. As long as the data in the database exists, Entity beans will survive. It is not based on the application or service process. Even if the EJB container crashes, Entity beans survive. Entity Beans can be managed by containers or Beans themselves.

EJB uses the following technical management practices: OTS of Object Management Organization (OMG), Transaction Service (JTS) of Sun Microsystems, and Java Transaction API (JTA ), the XA interface of the Development Group (X/Open.

  4. EJB roles and three objects

A: A complete EJB-based Distributed Computing structure consists of six roles, which can be provided by different developers, each role must follow the EJB specifications provided by Sun to ensure compatibility between them. These six roles are EJB component developer (Enterprise Bean Provider), Application aggreger (Application aggreger), Deployer (Deployer), and EJB Server Provider (EJB Server Provider), EJB Container Provider, System Administrator)

The three objects are Remote (Local) interface, Home (LocalHome) interface, and Bean class.
  5. Services provided by the EJB container

 

A: It mainly provides services such as declarative cycle management, code generation, continuity management, security, transaction management, lock and release management.

  6. What operations are prohibited in ejbs In the EJB specification?

Answer: 1. the thread and thread APIs cannot be operated (the thread API refers to methods of non-thread objects, such as notify and wait. awt cannot be operated, 3. cannot implement server functions. 4. cannot survive the static genus. you cannot use IO operations to directly access the file system. 6. the local database cannot be loaded ., 7. you cannot use this as a variable or return value. it cannot be called cyclically.

  7. Main Functions of the remote interface and home interface

A: The remote interface defines the business method used by the EJB client to call the business method.

The home interface is used by the EJB factory to create and remove EJB instances.

  8. bean instance Lifecycle

A: For Stateless Session Bean, Entity Bean, and Message Driven Bean, buffer pool management is generally available. For Entity Bean and Statefull Session Bean, Cache Management is available, which usually includes instance creation, set the context, create an EJB Object (create), call a business method, and remove. For beans with buffer pool management, the instance is not cleared from the memory after create, instead, the buffer pool scheduling mechanism is used to repeatedly reuse instances. For beans with Cache Management, the activation and deactivation mechanisms are used to maintain the Bean status and limit the number of instances in the memory.

  9. EJB activation mechanism

A: Taking Stateful Session Bean as an example: the Cache size determines the number of Bean instances that can coexist in the memory. According to the MRU or NRU algorithm, instances are migrated between the activation and deactivation statuses, the activation mechanism is that when the client calls a business method of an EJB instance, if the corresponding EJB Object finds that it is not bound to the corresponding Bean instance, it will activate Bean storage from it (storage instance through serialization mechanism) reply (activate) this instance. The corresponding ejbActive and ejbPassivate methods are called before the status changes.

  10. Several EJB types

Answer: Session Bean, Message Driven Bean Driven by Entity Bean

Session beans can be divided into Stateful and Stateless.

Entity beans can be divided into two types: Bean management continuity (BMP) and container management continuity (CMP ).

  11. client-side basic steps for calling EJB objects

A: set the properties of the jndi service factory and the JNDI service address system, find the Home interface, call the Create method from the Home interface to Create a Remote interface, and call its business method through the Remote interface.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.