Why EJB?

Source: Internet
Author: User

First, we must clarify why J2EE is used? What are the advantages of J2EE? The main reason for using J2EE is the multi-layer structure. The traditional two-layer C/S structure is difficult to maintain, and the stability is very poor. The interface code and database code are mixed together, bringing a hundred changes, the multi-layer structure completely separates the interface from the database, and introduces the middleware technology, such:

Web + EJB can form a true multi-layer structure
I originally thought this was not a topic of discussion about how to use EJB. Because EJB is an important part of J2EE, it can be said that J2EE without EJB is just a Web system, such a system can easily lose most of the advantages of multi-layer structure (think carefully about the differences between those JavaBeans that mix multiple levels of functions and the traditional two-layer structure ?).

Of course, layers can be artificially divided between Javabeans. For example, Hibernate calculates the data persistence layer. Some JavaBeans are the business core layer, but because they are all common JavaBeans, this division is not mandatory and obviously iconic, if such a system is replaced by a primary engineer or designer, it may be very messy for new programmers.

Let's first look at how a J2EE system containing EJB clearly expresses the hierarchy. For example:

The Web is just an implementation of the MVC model, and the core of the key business is implemented at the EJB service layer. The advantage of this is that the Web is only responsible for interface-related parts, because, if it is a smart client, such as Swing or J2EE, it can be easily replaced without modifying any business core. Similarly, the Web Services feature is only modified at the Web layer, and does not involve EJB modifications. It also ensures system stability and system upgrade and future scalability.

If you do not use EJB, the Business Core implemented at the EJB service layer will be implemented by the common JavaBeans. The architecture or design used can ensure that the MVC ans responsible for MVC and the JavaBeans responsible for the Business Core are clearly separated, how can we ensure that new programmers will not disrupt and disrupt your well-laid JavaBeans architecture?

EJB provides performance optimization support
The most important problem is the performance. Some Chinese Java websites have bent the EJB and think that the EJB performance is low. In fact, this is a very superficial misunderstanding, first, let's look at how to improve performance in general Java environments.

If A JavaBeans is A, the following command is generally used:

A a = new ();

However, in A high-traffic environment, new A () consumes A lot of time and system performance. Therefore, can we create some objects in advance when the software system is started, when the system is running, borrow one from these generated object pools. In this way, you do not need to perform New operations during use, saving the overhead and improving the performance. Therefore, real mature performance solutions require the support of object pools.

In a pure Web system (that is, it can only run in the Tomat environment), such as Struts + Hibernate and other systems, unless you do it yourself, there is generally no technical support for the object pool, therefore, their performance can only be regarded as the performance of the Demo version. It cannot afford high-capacity concurrent access, nor can it be called a mature system. Therefore, we study mature open-source Web systems, for example, Jive, OFBize, and LifeRay all have their own object pool and cache pool on the Web layer.

Is the object pool and cache mechanism required by J2EE? Of course, it is essential for all mature systems. What will happen if the Windows system removes the cache?

It is not a simple task to develop the object pool and cache mechanism by yourself. You must have a deep understanding of underlying principles such as multithreading and synchronization locks, this is actually a very in-depth Java Research Branch, so you can leave your customer's anxious urging to carefully study and develop your own object pool and cache pool.

However, the EJB container (such as JBoss) already provides an object pool and cache mechanism. Therefore, the performance of stateless Session beans without a transaction mechanism must be better than that of normal JavaBeans. The EJB container not only provides the object pool and cache in a single machine, but also can achieve dynamic load balancing across servers. These do not require developers to develop any software code. The structure is as follows:

EJB components provide a real reusable framework
Each jar package represents an EJB component. A system can be composed of multiple reusable EJB components, such as the tree-structure EJB component, auto-incrementing number EJB component, and user data EJB component, such EJB components can be combined in most application systems like building blocks, improving the system development efficiency and ensuring the development quality.

Is the EJB component diagram that should be used in a new system. In this new application, a large number of reusable EJB components are used, the new development work is basically focused on the interface design and process arrangement:

EJB provides a transaction mechanism
The transaction mechanism is very important for some key transactions, such as ATM withdrawals and withdrawals. There are multiple actions: modifying the database and counting the money. If any of these steps goes wrong, other operations that have already been implemented must be restored. Otherwise, it will appear that the payer did not get the money, but the deduction on the card and other incredible events have occurred.

The transaction mechanism provided by EJB is very comprehensive, but the disadvantage of the transaction mechanism is the performance reduction. Therefore, some people think that EJB is very heavy, because in actual application, some user systems may not need the transaction mechanism, but only the performance optimization mechanism provided by ejbs. In this way, if EJB is used, it is like a person carrying things, except what I want, carrying something I don't want.

Unless you are a perfectionist, in general enterprise applications or database system applications, ejbs do not pose a heavy burden on you.

Unique Advantages of CMP
Open source and some database persistence layer technology fans have been attacking CMP and think that CMP is slow and useless. The biggest problem is their design and use.

As the EJB container (such as JBoss) implements Cache Optimization with a transaction mechanism for CMP, CMP is especially suitable for multiple users to update the same data source at the same time, CMP's strict transaction integrity ensures performance optimization and data integrity when multiple users operate on one data record at the same time. If this data record is a status sign of the software system, its status will affect many links in the system, so the importance of state change is self-evident.

Without support for transaction integrity, your software system becomes more accessible to users, and various impossible logical errors may occur. Check that the program logic is correct. Where is the problem? Data Integrity.

Since each CMP has a cache in the memory, in actual applications, if you use CMP to read database data in batches, tens of thousands of queries are completed, and the memory is filled with tens of thousands of CMP caches, if your EJB container is improperly set at this time (for example, the default JBoss configuration is used), the JVM garbage collection mechanism will be started frequently, causing your system to slow down or even crash, this is also the reason why some people criticize the slow CMP. In fact, they are not using the method improperly or are not correctly configuring the EJB container CMP cache.

In this case, the DAO + JDBC method is recommended based on the J2EE Core mode.

Summary
Unless you have a deep understanding of the design pattern, you can use the JavaBeans usage pattern or some framework in your system to perform a fixed layering. At the same time, you have worked tirelessly to develop an object pool and are proficient in JTA and other transaction mechanisms, you can choose a pure Web structure without EJB, just like Jive and OFBiz. Of course, there is also a premise that the boss does not understand or is very challenging (to be a company and technology that is the same as ibm sun Microsoft ).

Don't be misled by the enthusiastic open-source engineers of TSS. They have time to ensure that they can do what they like. As a professional J2EE programmer, they should learn and act according to the J2EE standard, one of the technologies of J2EE, such as Jsp or JavaBeans, is safe to think that its system is J2EE.

Of course, I am not saying that a pure Web system cannot implement a multi-layer structure, but at least in many ways the Web + EJB structure is not perfect and clear. Therefore, EJB is not a part that J2EE can ignore, it is an important part. The core of important business functions is encapsulated in EJB. On the contrary, the Web layer is a secondary layer related to the interface.

EJB components provide a real reusable framework
Each jar package represents an EJB component. A system can be composed of multiple reusable EJB components, such as the tree-structure EJB component, auto-incrementing number EJB component, and user data EJB component, such EJB components can be combined in most application systems like building blocks, improving the system development efficiency and ensuring the development quality.

Is the EJB component diagram that should be used in a new system. In this new application, a large number of reusable EJB components are used, the new development work is basically focused on the interface design and process arrangement:

EJB provides a transaction mechanism
The transaction mechanism is very important for some key transactions, such as ATM withdrawals and withdrawals. There are multiple actions: modifying the database and counting the money. If any of these steps goes wrong, other operations that have already been implemented must be restored. Otherwise, it will appear that the payer did not get the money, but the deduction on the card and other incredible events have occurred.

The transaction mechanism provided by EJB is very comprehensive, but the disadvantage of the transaction mechanism is the performance reduction. Therefore, some people think that EJB is very heavy, because in actual application, some user systems may not need the transaction mechanism, but only the performance optimization mechanism provided by ejbs. In this way, if EJB is used, it is like a person carrying things, except what I want, carrying something I don't want.

Unless you are a perfectionist, in general enterprise applications or database system applications, ejbs do not pose a heavy burden on you.

Unique Advantages of CMP
Open source and some database persistence layer technology fans have been attacking CMP and think that CMP is slow and useless. The biggest problem is their design and use.

As the EJB container (such as JBoss) implements Cache Optimization with a transaction mechanism for CMP, CMP is especially suitable for multiple users to update the same data source at the same time, CMP's strict transaction integrity ensures performance optimization and data integrity when multiple users operate on one data record at the same time. If this data record is a status sign of the software system, its status will affect many links in the system, so the importance of state change is self-evident.

Without support for transaction integrity, your software system becomes more accessible to users, and various impossible logical errors may occur. Check that the program logic is correct. Where is the problem? Data Integrity.

Since each CMP has a cache in the memory, in actual applications, if you use CMP to read database data in batches, tens of thousands of queries are completed, and the memory is filled with tens of thousands of CMP caches, if your EJB container is improperly set at this time (for example, the default JBoss configuration is used), the JVM garbage collection mechanism will be started frequently, causing your system to slow down or even crash, this is also the reason why some people criticize the slow CMP. In fact, they are not using the method improperly or are not correctly configuring the EJB container CMP cache.

In this case, the DAO + JDBC method is recommended based on the J2EE Core mode.

Summary
Unless you have a deep understanding of the design pattern, you can use the JavaBeans usage pattern or some framework in your system to perform a fixed layering. At the same time, you have worked tirelessly to develop an object pool and are proficient in JTA and other transaction mechanisms, you can choose a pure Web structure without EJB, just like Jive and OFBiz. Of course, there is also a premise that the boss does not understand or is very challenging (to be a company and technology that is the same as ibm sun Microsoft ).

Don't be misled by the enthusiastic open-source engineers of TSS. They have time to ensure that they can do what they like. As a professional J2EE programmer, they should learn and act according to the J2EE standard, one of the technologies of J2EE, such as Jsp or JavaBeans, is safe to think that its system is J2EE.

Of course, I am not saying that a pure Web system cannot implement a multi-layer structure, but at least in many ways the Web + EJB structure is not perfect and clear. Therefore, EJB is not a part that J2EE can ignore, it is an important part. The core of important business functions is encapsulated in EJB. On the contrary, the Web layer is a secondary layer related to the interface.

Web + EJB can form a true multi-layer structure
I originally thought this was not a topic of discussion about how to use EJB. Because EJB is an important part of J2EE, it can be said that J2EE without EJB is just a Web system, such a system can easily lose most of the advantages of multi-layer structure (think carefully about the differences between those JavaBeans that mix multiple levels of functions and the traditional two-layer structure ?).

Of course, layers can be artificially divided between Javabeans. For example, Hibernate calculates the data persistence layer. Some JavaBeans are the business core layer, but because they are all common JavaBeans, this division is not mandatory and obviously iconic, if such a system is replaced by a primary engineer or designer, it may be very messy for new programmers.

Let's first look at how a J2EE system containing EJB clearly expresses the hierarchy. For example:

The Web is just an implementation of the MVC model, and the core of the key business is implemented at the EJB service layer. The advantage of this is that the Web is only responsible for interface-related parts, because, if it is a smart client, such as Swing or J2EE, it can be easily replaced without modifying any business core. Similarly, the Web Services feature is only modified at the Web layer, and does not involve EJB modifications. It also ensures system stability and system upgrade and future scalability.

If you do not use EJB, the Business Core implemented at the EJB service layer will be implemented by the common JavaBeans. The architecture or design used can ensure that the MVC ans responsible for MVC and the JavaBeans responsible for the Business Core are clearly separated, how can we ensure that new programmers will not disrupt and disrupt your well-laid JavaBeans architecture?

EJB provides performance optimization support
The most important problem is the performance. Some Chinese Java websites have bent the EJB and think that the EJB performance is low. In fact, this is a very superficial misunderstanding, first, let's look at how to improve performance in general Java environments.

If A JavaBeans is A, the following command is generally used:

A a = new ();

However, in A high-traffic environment, new A () consumes A lot of time and system performance. Therefore, can we create some objects in advance when the software system is started, when the system is running, borrow one from these generated object pools. In this way, you do not need to perform New operations during use, saving the overhead and improving the performance. Therefore, real mature performance solutions require the support of object pools.

In a pure Web system (that is, it can only run in the Tomat environment), such as Struts + Hibernate and other systems, unless you do it yourself, there is generally no technical support for the object pool, therefore, their performance can only be regarded as the performance of the Demo version. It cannot afford high-capacity concurrent access, nor can it be called a mature system. Therefore, we study mature open-source Web systems, for example, Jive, OFBize, and LifeRay all have their own object pool and cache pool on the Web layer.

Is the object pool and cache mechanism required by J2EE? Of course, it is essential for all mature systems. What will happen if the Windows system removes the cache?

It is not a simple task to develop the object pool and cache mechanism by yourself. You must have a deep understanding of underlying principles such as multithreading and synchronization locks, this is actually a very in-depth Java Research Branch, so you can leave your customer's anxious urging to carefully study and develop your own object pool and cache pool.

However, the EJB container (such as JBoss) already provides an object pool and cache mechanism. Therefore, the performance of stateless Session beans without a transaction mechanism must be better than that of normal JavaBeans. The EJB container not only provides the object pool and cache in a single machine, but also can achieve dynamic load balancing across servers. These do not require developers to develop any software code. The structure is as follows:

EJB components provide a real reusable framework
Each jar package represents an EJB component. A system can be composed of multiple reusable EJB components, such as the tree-structure EJB component, auto-incrementing number EJB component, and user data EJB component, such EJB components can be combined in most application systems like building blocks, improving the system development efficiency and ensuring the development quality.

Is the EJB component diagram that should be used in a new system. In this new application, a large number of reusable EJB components are used, the new development work is basically focused on the interface design and process arrangement:

EJB provides a transaction mechanism
The transaction mechanism is very important for some key transactions, such as ATM withdrawals and withdrawals. There are multiple actions: modifying the database and counting the money. If any of these steps goes wrong, other operations that have already been implemented must be restored. Otherwise, it will appear that the payer did not get the money, but the deduction on the card and other incredible events have occurred.

The transaction mechanism provided by EJB is very comprehensive, but the disadvantage of the transaction mechanism is the performance reduction. Therefore, some people think that EJB is very heavy, because in actual application, some user systems may not need the transaction mechanism, but only the performance optimization mechanism provided by ejbs. In this way, if EJB is used, it is like a person carrying things, except what I want, carrying something I don't want.

Unless you are a perfectionist, in general enterprise applications or database system applications, ejbs do not pose a heavy burden on you.

Unique Advantages of CMP
Open source and some database persistence layer technology fans have been attacking CMP and think that CMP is slow and useless. The biggest problem is their design and use.

As the EJB container (such as JBoss) implements Cache Optimization with a transaction mechanism for CMP, CMP is especially suitable for multiple users to update the same data source at the same time, CMP's strict transaction integrity ensures performance optimization and data integrity when multiple users operate on one data record at the same time. If this data record is a status sign of the software system, its status will affect many links in the system, so the importance of state change is self-evident.

Without support for transaction integrity, your software system becomes more accessible to users, and various impossible logical errors may occur. Check that the program logic is correct. Where is the problem? Data Integrity.

Since each CMP has a cache in the memory, in actual applications, if you use CMP to read database data in batches, tens of thousands of queries are completed, and the memory is filled with tens of thousands of CMP caches, if your EJB container is improperly set at this time (for example, the default JBoss configuration is used), the JVM garbage collection mechanism will be started frequently, causing your system to slow down or even crash, this is also the reason why some people criticize the slow CMP. In fact, they are not using the method improperly or are not correctly configuring the EJB container CMP cache.

In this case, the DAO + JDBC method is recommended based on the J2EE Core mode.

Summary
Unless you have a deep understanding of the design pattern, you can use the JavaBeans usage pattern or some framework in your system to perform a fixed layering. At the same time, you have worked tirelessly to develop an object pool and are proficient in JTA and other transaction mechanisms, you can choose a pure Web structure without EJB, just like Jive and OFBiz. Of course, there is also a premise that the boss does not understand or is very challenging (to be a company and technology that is the same as ibm sun Microsoft ).

Don't be misled by the enthusiastic open-source engineers of TSS. They have time to ensure that they can do what they like. As a professional J2EE programmer, they should learn and act according to the J2EE standard, one of the technologies of J2EE, such as Jsp or JavaBeans, is safe to think that its system is J2EE.

Of course, I am not saying that a pure Web system cannot implement a multi-layer structure, but at least in many ways the Web + EJB structure is not perfect and clear. Therefore, EJB is not a part that J2EE can ignore, it is an important part. The core of important business functions is encapsulated in EJB. On the contrary, the Web layer is a secondary layer related to the interface.

EJB components provide a real reusable framework
Each jar package represents an EJB component. A system can be composed of multiple reusable EJB components, such as the tree-structure EJB component, auto-incrementing number EJB component, and user data EJB component, such EJB components can be combined in most application systems like building blocks, improving the system development efficiency and ensuring the development quality.

Is the EJB component diagram that should be used in a new system. In this new application, a large number of reusable EJB components are used, the new development work is basically focused on the interface design and process arrangement:

EJB provides a transaction mechanism
The transaction mechanism is very important for some key transactions, such as ATM withdrawals and withdrawals. There are multiple actions: modifying the database and counting the money. If any of these steps goes wrong, other operations that have already been implemented must be restored. Otherwise, it will appear that the payer did not get the money, but the deduction on the card and other incredible events have occurred.

The transaction mechanism provided by EJB is very comprehensive, but the disadvantage of the transaction mechanism is the performance reduction. Therefore, some people think that EJB is very heavy, because in actual application, some user systems may not need the transaction mechanism, but only the performance optimization mechanism provided by ejbs. In this way, if EJB is used, it is like a person carrying things, except what I want, carrying something I don't want.

Unless you are a perfectionist, in general enterprise applications or database system applications, ejbs do not pose a heavy burden on you.

Unique Advantages of CMP
Open source and some database persistence layer technology fans have been attacking CMP and think that CMP is slow and useless. The biggest problem is their design and use.

As the EJB container (such as JBoss) implements Cache Optimization with a transaction mechanism for CMP, CMP is especially suitable for multiple users to update the same data source at the same time, CMP's strict transaction integrity ensures performance optimization and data integrity when multiple users operate on one data record at the same time. If this data record is a status sign of the software system, its status will affect many links in the system, so the importance of state change is self-evident.

Without support for transaction integrity, your software system becomes more accessible to users, and various impossible logical errors may occur. Check that the program logic is correct. Where is the problem? Data Integrity.

Since each CMP has a cache in the memory, in actual applications, if you use CMP to read database data in batches, tens of thousands of queries are completed, and the memory is filled with tens of thousands of CMP caches, if your EJB container is improperly set at this time (for example, the default JBoss configuration is used), the JVM garbage collection mechanism will be started frequently, causing your system to slow down or even crash, this is also the reason why some people criticize the slow CMP. In fact, they are not using the method improperly or are not correctly configuring the EJB container CMP cache.

In this case, the DAO + JDBC method is recommended based on the J2EE Core mode.

Summary
Unless you have a deep understanding of the design pattern, you can use the JavaBeans usage pattern or some framework in your system to perform a fixed layering. At the same time, you have worked tirelessly to develop an object pool and are proficient in JTA and other transaction mechanisms, you can choose a pure Web structure without EJB, just like Jive and OFBiz. Of course, there is also a premise that the boss does not understand or is very challenging (to be a company and technology that is the same as ibm sun Microsoft ).

Don't be misled by the enthusiastic open-source engineers of TSS. They have time to ensure that they can do what they like. As a professional J2EE programmer, they should learn and act according to the J2EE standard, one of the technologies of J2EE, such as Jsp or JavaBeans, is safe to think that its system is J2EE.

Of course, I am not saying that a pure Web system cannot implement a multi-layer structure, but at least in many ways the Web + EJB structure is not perfect and clear. Therefore, EJB is not a part that J2EE can ignore, it is an important part. The core of important business functions is encapsulated in EJB. On the contrary, the Web layer is a secondary layer related to the interface.

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.